MCPcopy
hub / github.com/coder/mux / cleanupTestEnvironment

Function cleanupTestEnvironment

tests/ipc/setup.ts:104–129  ·  view source on GitHub ↗
(env: TestEnvironment)

Source from the content-addressed store, hash-verified

102 * Cleanup test environment (remove temporary directory) with retry logic
103 */
104export async function cleanupTestEnvironment(env: TestEnvironment): Promise<void> {
105 // Best-effort: dispose services to prevent leaked intervals/background processes.
106 try {
107 await env.services.dispose();
108 await env.services.shutdown();
109 } catch (error) {
110 console.warn("Failed to dispose test services:", error);
111 }
112
113 const maxRetries = 3;
114 let lastError: unknown;
115
116 for (let i = 0; i < maxRetries; i++) {
117 try {
118 await fs.rm(env.tempDir, { recursive: true, force: true });
119 return;
120 } catch (error) {
121 lastError = error;
122 // Wait before retry (files might be locked temporarily)
123 if (i < maxRetries - 1) {
124 await new Promise((resolve) => setTimeout(resolve, 100 * (i + 1)));
125 }
126 }
127 }
128 console.warn(`Failed to cleanup test environment after ${maxRetries} attempts:`, lastError);
129}
130
131/**
132 * Setup provider configuration via IPC

Callers 15

cleanupFunction · 0.90
truncation.test.tsFile · 0.90
disposeFunction · 0.90
createCreationHarnessFunction · 0.90
disposeFunction · 0.90
createAppHarnessFunction · 0.90

Calls 2

disposeMethod · 0.65
shutdownMethod · 0.45

Tested by 4

cleanupFunction · 0.72
disposeFunction · 0.72
createCreationHarnessFunction · 0.72