The read timeout on a Postgres connection cannot be set with standard properties. We have to use a custom property under the following key.
spring.datasource.hikari.data-source-properties
A list of properties that can be used for the Postgres driver can be found on this page.
So, in order to set the socket timeout, we have to set the following key.
spring.datasource.hikari.data-source-properties.socketTimeout=20
To test the timeout, we need to be able to control how long it takes to perform a query. I found having an explicit sleep in the query sent to Postgres was the easiest solution. You can do this by adding pg_sleep to your query. For example, if you want to delay fetching a record with a query like this:
SELECT * FROM some_table
You could use pg_sleep
in the following manner:
SELECT *, pg_sleep(10) FROM some_table
The query will now be delayed by (at least) 10 seconds and return an extra column in addition to the columns in the table.