From ed8467440e87baf040f94567d09d190be47bf06d Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Mon, 31 Oct 2022 16:52:28 -0700 Subject: [PATCH 1/2] Add missing promise resolution for graceful stop case --- src/execution/service.ts | 2 ++ src/test/service.test.ts | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/execution/service.ts b/src/execution/service.ts index b2eecfd57..c8967077a 100644 --- a/src/execution/service.ts +++ b/src/execution/service.ts @@ -746,6 +746,8 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand { + // consumer + // | + // v + // service + + const consumer = await rig.newCommand(); + const service = await rig.newCommand(); + await rig.writeAtomic({ + 'package.json': { + scripts: { + consumer: 'wireit', + service: 'wireit', + }, + wireit: { + consumer: { + command: consumer.command, + dependencies: ['service'], + files: [], + output: [], + }, + service: { + command: service.command, + service: true, + files: ['input'], + }, + }, + }, + }); + + await rig.write('input', 'A'); + const wireit = rig.exec('npm run consumer --watch'); + + // 1st run with input A. Runs. + { + const serviceInv = await service.nextInvocation(); + const consumerInv1 = await consumer.nextInvocation(); + consumerInv1.exit(0); + await serviceInv.closed; + await wireit.waitForLog(/Watching for file changes/); + assert.equal(service.numInvocations, 1); + assert.equal(consumer.numInvocations, 1); + } + + // 2nd run with input B. Runs. + { + await rig.write('input', 'B'); + const serviceInv = await service.nextInvocation(); + const consumerInv1 = await consumer.nextInvocation(); + consumerInv1.exit(0); + await serviceInv.closed; + await wireit.waitForLog(/Watching for file changes/); + assert.equal(service.numInvocations, 2); + assert.equal(consumer.numInvocations, 2); + } + + // 3rd run with input A. Restored from cache. + { + await rig.write('input', 'A'); + await wireit.waitForLog(/Restored from cache/); + await wireit.waitForLog(/Watching for file changes/); + assert.equal(service.numInvocations, 2); + assert.equal(consumer.numInvocations, 2); + } + + wireit.kill(); + await wireit.exit; + assert.equal(service.numInvocations, 2); + assert.equal(consumer.numInvocations, 2); + }) +); + test.run(); From c7fb9174f5cd19d62b4414a3bea73f272662d5de Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Tue, 1 Nov 2022 11:18:47 -0700 Subject: [PATCH 2/2] Address PR feedback --- src/execution/service.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/execution/service.ts b/src/execution/service.ts index c8967077a..e8dfe9e60 100644 --- a/src/execution/service.ts +++ b/src/execution/service.ts @@ -684,11 +684,7 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand