Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
THardy98 committed Feb 7, 2025
1 parent af0754e commit 3261083
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
13 changes: 10 additions & 3 deletions packages/test/src/test-integration-split-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,12 @@ test('Workflow can upsert Search Attributes', configMacro, async (t, config) =>
);
});

export async function returnWorkflowInfo(): Promise<WorkflowInfo> {
return workflowInfo();
export async function returnWorkflowInfo(): Promise<WorkflowInfo & { isTypedSearchAttributesInstance: boolean }> {
const info = workflowInfo();
return {
...info,
isTypedSearchAttributesInstance: info.typedSearchAttributes instanceof TypedSearchAttributes,
};
}

test('Workflow can read WorkflowInfo', configMacro, async (t, config) => {
Expand All @@ -724,7 +728,10 @@ test('Workflow can read WorkflowInfo', configMacro, async (t, config) => {
runId: handle.firstExecutionRunId,
taskQueue,
searchAttributes: {},
typedSearchAttributes: new TypedSearchAttributes(),
// Ensure serialized data structure is correct
typedSearchAttributes: JSON.parse(JSON.stringify(new TypedSearchAttributes())),
// Ensure typed search attributes in workflow info is an instance of TypedSearchAttributes
isTypedSearchAttributesInstance: true,
workflowType: 'returnWorkflowInfo',
workflowId: handle.workflowId,
historyLength: 3,
Expand Down
50 changes: 27 additions & 23 deletions packages/test/src/test-schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SearchAttributes,
} from '@temporalio/client';
import { msToNumber } from '@temporalio/common/lib/time';
import { searchAttributePair, SearchAttributeType } from '@temporalio/common';
import { searchAttributePair, SearchAttributeType, TypedSearchAttributes } from '@temporalio/common';
import { registerDefaultCustomSearchAttributes, RUN_INTEGRATION_TESTS } from './helpers';

export interface Context {
Expand Down Expand Up @@ -169,7 +169,7 @@ if (RUN_INTEGRATION_TESTS) {
searchAttributes: {
CustomKeywordField: ['test-value2'],
},
typedSearchAttributes: [searchAttributePair('CustomInt', SearchAttributeType.INT, 42)],
typedSearchAttributes: [searchAttributePair('CustomIntField', SearchAttributeType.INT, 42)],
},
});

Expand All @@ -179,15 +179,17 @@ if (RUN_INTEGRATION_TESTS) {
t.is(describedSchedule.action.type, 'startWorkflow');
t.is(describedSchedule.action.workflowType, 'dummyWorkflow');
t.deepEqual(describedSchedule.action.memo, { 'my-memo': 'foo' });
t.deepEqual(describedSchedule.action.searchAttributes, [
['CustomKeywordField', ['test-value2']],
['CustomInt', 42],
]);
t.deepEqual(describedSchedule.action.typedSearchAttributes, [
searchAttributePair('CustomInt', SearchAttributeType.INT, 42),
// Note that the typed search attribute infers type TEXT from the value.
searchAttributePair('CustomKeywordField', SearchAttributeType.TEXT, 'test-value2'),
]);
t.deepEqual(describedSchedule.action.searchAttributes, {
CustomKeywordField: ['test-value2'],
CustomIntField: [42],
});
t.deepEqual(
describedSchedule.action.typedSearchAttributes,
new TypedSearchAttributes([
searchAttributePair('CustomIntField', SearchAttributeType.INT, 42),
searchAttributePair('CustomKeywordField', SearchAttributeType.KEYWORD, 'test-value2'),
])
);
} finally {
await handle.delete();
}
Expand All @@ -212,7 +214,7 @@ if (RUN_INTEGRATION_TESTS) {
searchAttributes: {
CustomKeywordField: ['test-value2'],
},
typedSearchAttributes: [searchAttributePair('CustomInt', SearchAttributeType.INT, 42)],
typedSearchAttributes: [searchAttributePair('CustomIntField', SearchAttributeType.INT, 42)],
},
});

Expand All @@ -223,15 +225,17 @@ if (RUN_INTEGRATION_TESTS) {
t.is(describedSchedule.action.workflowType, 'dummyWorkflowWith2Args');
t.deepEqual(describedSchedule.action.args, [3, 4]);
t.deepEqual(describedSchedule.action.memo, { 'my-memo': 'foo' });
t.deepEqual(describedSchedule.action.searchAttributes, [
['CustomKeywordField', ['test-value2']],
['CustomInt', 42],
]);
t.deepEqual(describedSchedule.action.typedSearchAttributes, [
searchAttributePair('CustomInt', SearchAttributeType.INT, 42),
// Note that the typed search attribute "guesses" TEXT, inferred from the value.
searchAttributePair('CustomKeywordField', SearchAttributeType.TEXT, 'test-value2'),
]);
t.deepEqual(describedSchedule.action.searchAttributes, {
CustomKeywordField: ['test-value2'],
CustomIntField: [42],
});
t.deepEqual(
describedSchedule.action.typedSearchAttributes,
new TypedSearchAttributes([
searchAttributePair('CustomIntField', SearchAttributeType.INT, 42),
searchAttributePair('CustomKeywordField', SearchAttributeType.KEYWORD, 'test-value2'),
])
);
} finally {
await handle.delete();
}
Expand Down Expand Up @@ -342,7 +346,7 @@ if (RUN_INTEGRATION_TESTS) {
searchAttributes: {
CustomKeywordField: ['test-value2'],
},
typedSearchAttributes: [searchAttributePair('CustomInt', SearchAttributeType.INT, 42)],
typedSearchAttributes: [searchAttributePair('CustomIntField', SearchAttributeType.INT, 42)],
},
});

Expand Down Expand Up @@ -587,7 +591,7 @@ if (RUN_INTEGRATION_TESTS) {
taskQueue,
},
searchAttributes,
typedSearchAttributes: [searchAttributePair('CustomInt', SearchAttributeType.INT, 42)],
typedSearchAttributes: [searchAttributePair('CustomIntField', SearchAttributeType.INT, 42)],
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/test/src/test-sinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (RUN_INTEGRATION_TESTS) {
memo: {},
parent: undefined,
searchAttributes: {},
typedSearchAttributes: new TypedSearchAttributes(),
typedSearchAttributes: JSON.parse(JSON.stringify(new TypedSearchAttributes())),
historyLength: 3,
continueAsNewSuggested: false,
// values ignored for the purpose of comparison
Expand Down
4 changes: 1 addition & 3 deletions packages/workflow/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,7 @@ export function makeContinueAsNewFunc<F extends Workflow>(
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo),
searchAttributes:
options.searchAttributes || options.typedSearchAttributes
? {
indexedFields: encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes),
}
? encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes)
: undefined,
workflowRunTimeout: msOptionalToTs(options.workflowRunTimeout),
workflowTaskTimeout: msOptionalToTs(options.workflowTaskTimeout),
Expand Down

0 comments on commit 3261083

Please sign in to comment.