rollbridge 0.1.68 → 0.1.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -176,6 +176,52 @@ test("shutdown keeps daemon services alive until release-owned dependents stop",
176
176
  }
177
177
  })
178
178
 
179
+ test("shutdown returns after the non-blocking drain budget instead of waiting for a worker", async () => {
180
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), "rollbridge-shutdown-non-blocking-drain-"))
181
+ const socketPath = path.join(root, "control.sock")
182
+ const readyPath = path.join(root, "ready")
183
+ const processCommand = `${JSON.stringify(process.execPath)} -e ${JSON.stringify(`process.on('SIGTERM', () => {}); require("node:fs").writeFileSync(${JSON.stringify(readyPath)}, "ready"); setInterval(() => {}, 1000)`)}`
184
+ const config = buildConfig(socketPath, {
185
+ companion: {command: processCommand, gracefulStopMs: "indefinite", id: "worker", nonBlockingDrain: true, policy: "companion"}
186
+ })
187
+ config.proxy.nonBlockingDrainTimeoutMs = 25
188
+ const daemon = new RollbridgeDaemon({config, logger: () => {}})
189
+ let workerPid
190
+
191
+ try {
192
+ await daemon.start()
193
+ await daemon.deploy({releaseId: "v1", releasePath: root, revision: "v1"})
194
+ await waitForFile(readyPath)
195
+ workerPid = daemon.activeRelease?.getProcess("worker")?.pid
196
+
197
+ expect(typeof workerPid).toBe("number")
198
+
199
+ let timer
200
+ try {
201
+ await Promise.race([
202
+ daemon.shutdown(),
203
+ new Promise((_, reject) => { timer = setTimeout(() => reject(new Error("shutdown waited past its retirement budget")), 1000) })
204
+ ])
205
+ } finally {
206
+ clearTimeout(timer)
207
+ }
208
+
209
+ let workerGroupAlive = true
210
+ try {
211
+ process.kill(-/** @type {number} */ (workerPid), 0)
212
+ } catch {
213
+ workerGroupAlive = false
214
+ }
215
+ expect(workerGroupAlive).toBe(true)
216
+ } finally {
217
+ if (workerPid) {
218
+ try { process.kill(-workerPid, "SIGKILL") } catch (_error) { /* Exact fixture process already exited. */ }
219
+ }
220
+ await daemon.shutdown().catch(() => {})
221
+ await fs.rm(root, {force: true, recursive: true})
222
+ }
223
+ })
224
+
179
225
  test("external-owner retirement releases listeners before a long-draining companion exits", async () => {
180
226
  const root = await fs.mkdtemp(path.join(os.tmpdir(), "rollbridge-owner-retirement-"))
181
227
  const socketPath = path.join(root, "rollbridge.sock")
@@ -401,6 +447,12 @@ function rawConfig(socketPath) {
401
447
  * @returns {Promise<void>} Resolves when the file appears.
402
448
  */
403
449
  async function waitForFile(filePath) {
450
+ try {
451
+ await fs.access(filePath)
452
+ return
453
+ } catch {
454
+ // The file may be created after the watcher is installed.
455
+ }
404
456
  const watcher = fs.watch(path.dirname(filePath))
405
457
 
406
458
  try {