How do I create a query which takes certain time to execute?
As @McNets suggests in his comment, this is really easy using the pg_sleep() function:
select pg_sleep(2);

will return after 2 seconds. And the resulting dataset will contain one row and one column too, so your test application can easily handle it (if it gets through the timeout).