fastmail / Ix

automatic generation of JMAP-style APIs
GNU General Public License v2.0
10 stars 5 forks source link

cache a schema connection to re-use in subsequent calls to PSGI sub #99

Closed rjbs closed 6 years ago

rjbs commented 6 years ago

Each PSGI app (subroutine) gets its own cache, but the caches are registered with the Ix::App object so that their caches can be cleared as needed to prepare to shutdown the system. In production, this is unlikely to be needed, but in testing we don't want lingering db connections at global destruction. DBD::Pg gets grumpy and complains.

Calling $app->_shutdown in each test is inelegant, but the TestInstance system (on another branch) ported from a downstream application can move the shutdown into the TestInstance's demolish, making the cleanup happen automatically in tests using a TestInstance.

Note: Rik isn't 100% sure why undefining the app sub isn't sufficient to clear the cache (in a world where we don't register caches with the Ix::App object). That may be worth looking into sometime.

With this change, the test suite drops nearly 200 connections in its total run, as most tests run through a single app object created in the test's prelude. With a TestInstance, this will happen behind the scenes.