@@ -168,16 +168,54 @@ export async function teardownE2ETestServer(server: E2ETestServer | undefined):
168168 console . error ( "Error closing Fastify server:" , error ) ;
169169 }
170170
171- if ( server . registryServer ) {
172- await stopMockRegistryServer ( server . registryServer ) ;
171+ // Close Neo4j DB service and driver before stopping containers
172+ if ( server . dbService ) {
173+ try {
174+ await server . dbService . close ( ) ;
175+ } catch ( error ) {
176+ console . error ( "Error closing DbService:" , error ) ;
177+ }
173178 }
174-
179+
180+ // Also close the raw Neo4j driver if available
181+ if ( server . neo4jDriver ) {
182+ try {
183+ await server . neo4jDriver . close ( ) ;
184+ } catch ( error ) {
185+ console . error ( "Error closing Neo4j driver:" , error ) ;
186+ }
187+ }
188+
189+ // Destroy PostgreSQL testDataSource
175190 if ( server . testDataSource ?. isInitialized ) {
176- await server . testDataSource . destroy ( ) ;
191+ try {
192+ await server . testDataSource . destroy ( ) ;
193+ } catch ( error ) {
194+ console . error ( "Error destroying testDataSource:" , error ) ;
195+ }
196+ }
197+
198+ // Stop registry server
199+ if ( server . registryServer ) {
200+ try {
201+ await stopMockRegistryServer ( server . registryServer ) ;
202+ } catch ( error ) {
203+ console . error ( "Error stopping registry server:" , error ) ;
204+ }
177205 }
178206
179- await teardownTestNeo4j ( ) ;
180- await teardownTestDatabase ( ) ;
207+ // Stop testcontainers
208+ try {
209+ await teardownTestNeo4j ( ) ;
210+ } catch ( error ) {
211+ console . error ( "Error tearing down Neo4j testcontainer:" , error ) ;
212+ }
213+
214+ try {
215+ await teardownTestDatabase ( ) ;
216+ } catch ( error ) {
217+ console . error ( "Error tearing down PostgreSQL testcontainer:" , error ) ;
218+ }
181219
182220 // Clean up environment variables
183221 delete process . env . NEO4J_URI ;
0 commit comments