Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions packages/test/src/test-workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ function makeActivation(
};
}

function makeUnblockTimer(timerId: string, timestamp: number = Date.now()): iface.coresdk.IWFActivation {
return makeActivation(timestamp, makeUnblockTimerJob(timerId));
function makeFireTimer(timerId: string, timestamp: number = Date.now()): iface.coresdk.IWFActivation {
return makeActivation(timestamp, makeFireTimerJob(timerId));
}

function makeUnblockTimerJob(timerId: string): iface.coresdk.IWFActivationJob {
function makeFireTimerJob(timerId: string): iface.coresdk.IWFActivationJob {
return {
timerFired: { timerId },
fireTimer: { timerId },
};
}

Expand Down Expand Up @@ -214,7 +214,7 @@ test('set-timeout', async (t) => {
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '0', startToFireTimeout: msToTs(100) })]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['slept']]);
Expand All @@ -227,7 +227,7 @@ test('set-timeout-after-microtasks', async (t) => {
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '0', startToFireTimeout: msToTs(100) })]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['slept']]);
Expand Down Expand Up @@ -261,7 +261,7 @@ test('tasks-and-microtasks', async (t) => {
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '0', startToFireTimeout: msToTs(0) })]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['script start'], ['script end'], ['promise1'], ['promise2'], ['setTimeout']]);
Expand All @@ -281,7 +281,7 @@ test('trailing-timer', async (t) => {
);
}
{
const req = await activate(t, makeActivation(undefined, makeUnblockTimerJob('0'), makeUnblockTimerJob('1')));
const req = await activate(t, makeActivation(undefined, makeFireTimerJob('0'), makeFireTimerJob('1')));
// Note that the trailing timer does not get scheduled since the workflow completes
// after the first timer is triggered causing the second one to be dropped.
compareCompletion(t, req, makeSuccess([makeCompleteWorkflowExecution(defaultDataConverter.toPayload('first'))]));
Expand All @@ -303,7 +303,7 @@ test('promise-race', async (t) => {
);
}
{
const req = await activate(t, makeActivation(undefined, makeUnblockTimerJob('0'), makeUnblockTimerJob('1')));
const req = await activate(t, makeActivation(undefined, makeFireTimerJob('0'), makeFireTimerJob('1')));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [[1], [1], [1], [1], [20], ['wow']]);
Expand All @@ -323,11 +323,11 @@ test('race', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess([]));
}
{
const req = await activate(t, makeUnblockTimer('1'));
const req = await activate(t, makeFireTimer('1'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [[1], [2], [3]]);
Expand All @@ -340,7 +340,7 @@ test('importer', async (t) => {
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '0', startToFireTimeout: msToTs(10) })]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['slept']]);
Expand Down Expand Up @@ -405,7 +405,7 @@ test('simple-query', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
{
Expand Down Expand Up @@ -450,7 +450,7 @@ test('cancel-workflow', async (t) => {
compareCompletion(t, req, makeSuccess([]));
}
{
const req = await activate(t, makeUnblockTimer('2'));
const req = await activate(t, makeFireTimer('2'));
compareCompletion(t, req, makeSuccess([makeCompleteWorkflowExecution(defaultDataConverter.toPayload({ url }))]));
}
t.deepEqual(logs, [['Workflow cancelled'], ['Workflow cancelled'], ['Workflow cancelled']]);
Expand Down Expand Up @@ -507,7 +507,7 @@ test('cancellation-scopes', async (t) => {
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '0', startToFireTimeout: msToTs(3) })]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(
t,
req,
Expand All @@ -519,7 +519,7 @@ test('cancellation-scopes', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('2'));
const req = await activate(t, makeFireTimer('2'));
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '3', startToFireTimeout: msToTs(3) })]));
}
{
Expand Down Expand Up @@ -549,11 +549,11 @@ test('child-and-shield', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess([]));
}
{
const req = await activate(t, makeUnblockTimer('1'));
const req = await activate(t, makeFireTimer('1'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['Exception was propagated 👍'], ['Slept in shield 👍']]);
Expand All @@ -573,7 +573,7 @@ test('partial-shield', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('1'));
const req = await activate(t, makeFireTimer('1'));
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '2', startToFireTimeout: msToTs(2) })]));
}
{
Expand All @@ -588,11 +588,11 @@ test('partial-shield', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess([makeStartTimerCommand({ timerId: '4', startToFireTimeout: msToTs(1) })]));
}
{
const req = await activate(t, makeUnblockTimer('3'));
const req = await activate(t, makeFireTimer('3'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [['Workflow cancelled']]);
Expand All @@ -612,11 +612,11 @@ test('shield-in-shield', async (t) => {
);
}
{
const req = await activate(t, makeUnblockTimer('1'));
const req = await activate(t, makeFireTimer('1'));
compareCompletion(t, req, makeSuccess([]));
}
{
const req = await activate(t, makeUnblockTimer('0'));
const req = await activate(t, makeFireTimer('0'));
compareCompletion(t, req, makeSuccess());
}
t.deepEqual(logs, [
Expand Down
26 changes: 13 additions & 13 deletions packages/workflow/src/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function timerIdToSeq(timerId: string | undefined | null) {
}

export class Activator implements WorkflowTaskHandler {
public startWorkflow(activation: iface.coresdk.IStartWorkflowTaskAttributes): void {
public startWorkflow(activation: iface.coresdk.IStartWorkflow): void {
if (state.workflow === undefined) {
throw new Error('state.workflow is not defined');
}
Expand All @@ -163,17 +163,17 @@ export class Activator implements WorkflowTaskHandler {
}
}

public cancelWorkflow(_activation: iface.coresdk.ICancelWorkflowTaskAttributes): void {
public cancelWorkflow(_activation: iface.coresdk.ICancelWorkflow): void {
state.cancelled = true;
rootScopeCancel(new CancellationError('Workflow cancelled'));
}

public timerFired(activation: iface.coresdk.ITimerFiredTaskAttributes): void {
public fireTimer(activation: iface.coresdk.IFireTimer): void {
const { resolve } = consumeCompletion(timerIdToSeq(activation.timerId));
resolve(undefined);
}

public timerCanceled(activation: iface.coresdk.ITimerCanceledTaskAttributes): void {
public cancelTimer(activation: iface.coresdk.ICancelTimer): void {
const { scope } = consumeCompletion(timerIdToSeq(activation.timerId));
try {
scope.cancel(new CancellationError('Timer cancelled'));
Expand All @@ -182,7 +182,7 @@ export class Activator implements WorkflowTaskHandler {
}
}

public queryWorkflow(job: iface.coresdk.IQueryWorkflowJob): void {
public queryWorkflow(job: iface.coresdk.IQueryWorkflow): void {
if (state.workflow === undefined) {
throw new Error('state.workflow is not defined');
}
Expand All @@ -208,7 +208,7 @@ export class Activator implements WorkflowTaskHandler {
}
}

public randomSeedUpdated(_activation: iface.coresdk.IRandomSeedUpdatedAttributes): void {
public updateRandomSeed(_activation: iface.coresdk.IUpdateRandomSeed): void {
throw new Error('Not implemented');
}
}
Expand All @@ -224,20 +224,20 @@ export function activate(encodedActivation: Uint8Array, jobIndex: number): boole
if (state.activator === undefined) {
throw new Error('state.activator is not defined');
}
if (job.attributes === undefined) {
throw new Error('Expected job.attributes to be defined');
if (job.variant === undefined) {
throw new Error('Expected job.variant to be defined');
}
const attrs = job[job.attributes];
if (!attrs) {
throw new Error(`Expected job.${job.attributes} to be set`);
const variant = job[job.variant];
if (!variant) {
throw new Error(`Expected job.${job.variant} to be set`);
}
// The only job that can be executed on a completed workflow is a query.
// We might get other jobs after completion for instance when a single
// activation contains multiple jobs and the first one completes the workflow.
if (state.completed && job.attributes !== 'queryWorkflow') {
if (state.completed && job.variant !== 'queryWorkflow') {
return false;
}
state.activator[job.attributes](attrs);
state.activator[job.variant](variant);
return true;
}

Expand Down