Flowminder / FlowKit

FlowKit: Flowminder CDR analytics toolkit
https://flowminder.github.io/FlowKit/
Mozilla Public License 2.0
86 stars 21 forks source link

Ensure no queries are running before resetting cache between integration tests #1245

Open jc-harrison opened 5 years ago

jc-harrison commented 5 years ago

At the start of each integration test, the cache and redis are reset. However, we don't check that all queries started by the previous test have finished before resetting, which can lead to errors. We should either wait for all running queries to finish, or explicitly kill them before resetting.

Note: I tried explicitly killing all queries by executing "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND application_name='{fm_conn.app_name}';", but this resulted in a lot of tests failing with InterfaceError: connection already closed. Also, I think even this would be insufficient, because if a thread has been started (in Query.thread_pool_executor) but hasn't started executing any SQL yet then it won't be killed by the pg_terminate_backend.

jc-harrison commented 5 years ago

A possible solution would be to get the list of all queries known to redis, and wait for all of these to be in a finished state before resetting FlowDB and redis. This wouldn't work in any situation where new queries could be submitted during the wait/reset process, but should be sufficient for resetting between integration tests.