Skip to content

Commit b001437

Browse files
Copilotvobu
andcommitted
fix: restore jobs --between tests with Camunda version skip, fix incident test race condition
Co-authored-by: vobu <6573426+vobu@users.noreply.github.com>
1 parent fcdd90f commit b001437

File tree

2 files changed

+77
-12
lines changed

2 files changed

+77
-12
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
7171
- name: Run integration tests
7272
run: npm run test:integration
73+
env:
74+
CAMUNDA_VERSION: ${{ matrix.camunda }}
7375

7476
- name: Stop Camunda
7577
if: always()

tests/integration/search.test.ts

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,14 @@ describe('Search Command Integration Tests (requires Camunda 8 at localhost:8080
581581

582582
test('searchIncidents with --between spanning today finds recently created incident', async () => {
583583
await deploy(['tests/fixtures/simple-will-create-incident.bpmn'], {});
584-
await createProcessInstance({ processDefinitionId: 'Process_0yyrstd' });
584+
const pi = await createProcessInstance({ processDefinitionId: 'Process_0yyrstd' });
585+
const piKey = String(pi!.processInstanceKey);
585586

586-
// Wait for the job and fail it to produce an incident
587+
// Wait for the job and fail it to produce an incident; filter by processInstanceKey to avoid
588+
// picking up jobs from previous tests that may still appear as CREATED in the search index
587589
let jobKey: string | undefined;
588590
const jobFound = await pollUntil(async () => {
589-
const result = await searchJobs({ type: 'unhandled-job-type', state: 'CREATED' });
591+
const result = await searchJobs({ type: 'unhandled-job-type', state: 'CREATED', processInstanceKey: piKey });
590592
if (result?.items && result.items.length > 0) {
591593
const job = result.items.find((j: any) => (j.state || '').toUpperCase() === 'CREATED') as any;
592594
if (job) {
@@ -611,10 +613,14 @@ describe('Search Command Integration Tests (requires Camunda 8 at localhost:8080
611613
assert.ok(found, '--between spanning today should find recently created incidents');
612614
});
613615

614-
// NOTE: searchJobs with --between is intentionally not tested here.
615-
// The `creationTime` and `lastUpdateTime` date filter fields for jobs
616-
// are only present in Camunda 8.9+ (see assets/c8/rest-api/jobs.yaml).
617-
// Testing them against Camunda 8.8 causes a "Bad Request" error.
616+
// Jobs --between tests require Camunda 8.9+ because `creationTime`/`lastUpdateTime` job search
617+
// filter fields are only available in 8.9+ (see assets/c8/rest-api/jobs.yaml).
618+
// Skip them when running against 8.8, using the CAMUNDA_VERSION env var set by the GH Actions matrix.
619+
const camundaVersion = process.env.CAMUNDA_VERSION;
620+
const isCamunda89Plus = camundaVersion !== '8.8';
621+
const jobsBetweenSkip = isCamunda89Plus
622+
? false
623+
: `creationTime job filter requires Camunda 8.9+ (CAMUNDA_VERSION=${camundaVersion ?? 'unset'})`;
618624

619625
test('list user-tasks --between via CLI does not error', async () => {
620626
await deploy(['tests/fixtures/list-pis'], {});
@@ -637,12 +643,14 @@ describe('Search Command Integration Tests (requires Camunda 8 at localhost:8080
637643

638644
test('list incidents --between via CLI does not error', async () => {
639645
await deploy(['tests/fixtures/simple-will-create-incident.bpmn'], {});
640-
await createProcessInstance({ processDefinitionId: 'Process_0yyrstd' });
646+
const pi = await createProcessInstance({ processDefinitionId: 'Process_0yyrstd' });
647+
const piKey = String(pi!.processInstanceKey);
641648

642-
// Wait for a job and fail it to produce an incident
649+
// Wait for a job and fail it to produce an incident; filter by processInstanceKey to avoid
650+
// picking up jobs from previous tests that may still appear as CREATED in the search index
643651
let jobKey: string | undefined;
644652
await pollUntil(async () => {
645-
const result = await searchJobs({ type: 'unhandled-job-type', state: 'CREATED' });
653+
const result = await searchJobs({ type: 'unhandled-job-type', state: 'CREATED', processInstanceKey: piKey });
646654
if (result?.items && result.items.length > 0) {
647655
const job = result.items.find((j: any) => (j.state || '').toUpperCase() === 'CREATED') as any;
648656
if (job) { jobKey = String(job.jobKey || job.key); return true; }
@@ -665,6 +673,61 @@ describe('Search Command Integration Tests (requires Camunda 8 at localhost:8080
665673

666674
assert.ok(typeof output === 'string', 'CLI should produce string output');
667675
});
668-
// NOTE: `list jobs --between` CLI is intentionally not tested here.
669-
// The `creationTime` date filter for jobs requires Camunda 8.9+ (see assets/c8/rest-api/jobs.yaml).
676+
677+
test('searchJobs with --between spanning today finds recently created job',
678+
{ skip: jobsBetweenSkip },
679+
async () => {
680+
await deploy(['tests/fixtures/simple-service-task.bpmn'], {});
681+
await createProcessInstance({ processDefinitionId: 'Process_18glkb3' });
682+
683+
const found = await pollUntil(async () => {
684+
const result = await searchJobs({
685+
type: 'n00b',
686+
state: 'CREATED',
687+
between: todayRange(),
688+
});
689+
return !!(result?.items && result.items.length > 0);
690+
}, POLL_TIMEOUT_MS, POLL_INTERVAL_MS);
691+
692+
assert.ok(found, '--between spanning today should find recently created jobs');
693+
});
694+
695+
test('searchJobs with --between and explicit --dateField=creationTime finds recently created job',
696+
{ skip: jobsBetweenSkip },
697+
async () => {
698+
await deploy(['tests/fixtures/simple-service-task.bpmn'], {});
699+
await createProcessInstance({ processDefinitionId: 'Process_18glkb3' });
700+
701+
const found = await pollUntil(async () => {
702+
const result = await searchJobs({
703+
type: 'n00b',
704+
between: todayRange(),
705+
dateField: 'creationTime',
706+
});
707+
return !!(result?.items && result.items.length > 0);
708+
}, POLL_TIMEOUT_MS, POLL_INTERVAL_MS);
709+
710+
assert.ok(found, '--between with --dateField=creationTime should find recently created jobs');
711+
});
712+
713+
test('list jobs --between via CLI does not error',
714+
{ skip: jobsBetweenSkip },
715+
async () => {
716+
await deploy(['tests/fixtures/simple-service-task.bpmn'], {});
717+
await createProcessInstance({ processDefinitionId: 'Process_18glkb3' });
718+
719+
// Wait for the job to be indexed
720+
await pollUntil(async () => {
721+
const result = await searchJobs({ type: 'n00b', state: 'CREATED' });
722+
return !!(result?.items && result.items.length > 0);
723+
}, POLL_TIMEOUT_MS, POLL_INTERVAL_MS);
724+
725+
const { execSync } = await import('node:child_process');
726+
const output = execSync(
727+
`node --no-warnings src/index.ts list jobs --between=${todayRange()}`,
728+
{ encoding: 'utf8', cwd: process.cwd() }
729+
);
730+
731+
assert.ok(typeof output === 'string', 'CLI should produce string output');
732+
});
670733
});

0 commit comments

Comments
 (0)