Skip to content

Commit

Permalink
fix(sdk): cloud.Service hangs on long-running inflight functions (#4089)
Browse files Browse the repository at this point in the history
Fixes #4086

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
Chriscbr authored Sep 7, 2023
1 parent 442df9a commit 2cc25e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/wingsdk/src/target-sim/service.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class Service implements IServiceClient, ISimulatorResourceInstance {
sourceType: SERVICE_TYPE,
timestamp: new Date().toISOString(),
});
await fnClient.invoke("");
// eslint-disable-next-line @typescript-eslint/no-floating-promises
fnClient.invoke("");
this.running = true;
}

Expand Down
31 changes: 31 additions & 0 deletions libs/wingsdk/test/target-sim/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ async handle(message) {
console.log("Service Started");
}`;

const INFLIGHT_ON_START_WITH_LOOP = `
async handle(message) {
console.log("Service Started");
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}`;

const INFLIGHT_ON_STOP = `
async handle(message) {
console.log("Service Stopped");
Expand Down Expand Up @@ -42,6 +50,29 @@ test("create a service with on start method", async () => {
expect(app.snapshot()).toMatchSnapshot();
});

test(
"on start method does not block other resources from deploying",
async () => {
// GIVEN
const app = new SimApp();
const handler = Testing.makeHandler(
app,
"OnStartHandler",
INFLIGHT_ON_START_WITH_LOOP
);
cloud.Service._newService(app, "my_service", {
onStart: handler,
});

// WHEN
const s = await app.startSimulator();

// THEN
await s.stop();
},
{ timeout: 10000 }
);

test("create a service with a on stop method", async () => {
// Given
const app = new SimApp();
Expand Down

0 comments on commit 2cc25e2

Please sign in to comment.