Steps to reproduce: Clone my project from GitHub and run all tests or alternatively duplicate the AcronymTests.swift file (in the folder “final” of chapter 11 or later) twice and rename the classes to AdditionalTests and AnotherSuiteOfTests (or whatever). Then run all the tests at once. It will fail at the 30th test which is more than the book offers.
The error reads: Thread 1: Fatal error: ‘try!’ expression unexpectedly raised an error: PostgreSQL Error: sorry, too many clients already
There’s a bug in Application and tests where it doesn’t close the PSQL connections properly. Can you try adding this to each test case’s shutdown? That apparently is a fix
Sadly that seems like it’s not the fix for my problem. I’m still getting the same error. If you want to try it yourself, I’ve added your proposed fix on branch #4 of my repo.
Hmm I’m wondering if there’s another issue. Are you on the Discord channel? Since the project is available on GH, it could be a good candidate to track the bug down.
Also, it may be worth investigating the repository pattern and abstracting away the database. This should significantly speed up the tests as a side benefit!
I get the same error, even with the syncShutdownGracefully() code in teardown.
The PostgreSQL connections start up and then go idle. Once you hit max_connections, the error kicks in!
I’m experimenting with a connection pool now to see if it makes a difference.
Same results using a connection pool. Looks like not all connections are getting closed.
I set postgreSQL to log connections and disconnections. If I run a test with 4 test cases, I wind up with 38 connections being made. If I let the test run to completion, all 38 connections get disconnected. However, if I put a breakpoint at the end of my last test case, I have 9 or 10 connections that don’t get disconnected until I resume after the breakpoint.