Skip to content

Commit

Permalink
Make locks for the top level function opt-in (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
avillega committed Aug 23, 2024
1 parent 387a48e commit 86725f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/resonate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export class Resonate {
*/
async start(delay: number = 5000) {
clearInterval(this.#interval);
this.#_start();
// await the first run of the recovery path to avoid races with the normal flow of the program
await this.#_start();
this.#interval = setInterval(this.#_start.bind(this), delay);
}

Expand Down Expand Up @@ -293,8 +294,8 @@ export class Resonate {
// resonate:invocation tag to identify a top level invocation
opts.tags = { ...registeredOpts.tags, ...tags, "resonate:invocation": "true" };

// lock on top level is true by default
opts.shouldLock = opts.shouldLock ?? true;
// locking is false by default
opts.shouldLock = opts.shouldLock ?? false;

const param = {
func: name,
Expand Down
8 changes: 3 additions & 5 deletions test/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Options", () => {
expect(opts.version).toBe(1);
}

expect(top.shouldLock).toBe(true);
expect(top.shouldLock).toBe(false);
expect(middle.shouldLock).toBe(false);
expect(bottom.shouldLock).toBe(false);

Expand Down Expand Up @@ -107,7 +107,7 @@ describe("Options", () => {
expect(top.eidFn).toBe(overrides.eidFn);
expect(top.encoder).toBe(resonateOpts.encoder);
expect(top.idempotencyKeyFn).toBe(overrides.idempotencyKeyFn);
expect(top.shouldLock).toBe(true);
expect(top.shouldLock).toBe(false);
expect(top.pollFrequency).toBe(resonateOpts.pollFrequency);
expect(top.retryPolicy).toBe(overrides.retryPolicy);
expect(top.tags).toEqual({ ...resonateOpts.tags, ...overrides.tags, "resonate:invocation": "true" });
Expand Down Expand Up @@ -157,15 +157,13 @@ describe("Options", () => {
expect(opts.pollFrequency).toBe(resonateOpts.pollFrequency);
expect(opts.retryPolicy).toBe(resonateOpts.retryPolicy);
expect(opts.timeout).toBe(resonateOpts.timeout);
expect(opts.shouldLock).toBe(false);
}

expect(top.version).toBe(1);
expect(middle.version).toBeDefined();
expect(bottom.version).toBeDefined();

expect(top.shouldLock).toBe(true);
expect(bottom.shouldLock).toBe(false);

expect(top.tags).toEqual({ ...resonateOpts.tags, "resonate:invocation": "true" });
expect(bottom.tags).toEqual(resonateOpts.tags);
});
Expand Down

0 comments on commit 86725f3

Please sign in to comment.