Leave TLS connection open in between tests
When I have 2 tests that use a database connection and attempt to close the connection
afterAll
the tests, the first fails because there's an open tls connection. Is it possible to leave the connection is open at the end of the first test?
results in
Thanks in advance!2 Replies
Based on the documentation, Deno's test runner includes a resource sanitizer that checks if all resources created during a test are closed before the test ends. This is to prevent resource leaks. By default, this sanitizer is enabled for all tests.
In your case, the error message indicates that a TCP connection (which is used for the TLS connection to your database) was opened during the test but not closed. This is considered a resource leak, and Deno's test runner will fail the test because of it.
If you want to keep the connection open between tests, you could disable the resource sanitizer for these tests by setting
sanitizeResources: false
in the test definition. However, this is generally not recommended because it could lead to actual resource leaks, especially if you forget to close the connection manually.
Here's how you could modify your tests to disable the resource sanitizer:
However, a better approach would be to manage the database connection in a way that it gets closed after each test or after all tests have run. This way, you ensure that no resources are leaked and you don't need to disable the resource sanitizer.
Please note that this information is not explicitly stated in the documentation, but is a general advice based on the principles of resourcemanagement in testing.