Skip to content

Conversation

@kirrg001
Copy link
Contributor

@kirrg001 kirrg001 commented Sep 16, 2025

See comments.

@kirrg001 kirrg001 changed the title test: corrected bull test cases test: corrected and clarified bull test cases Sep 16, 2025
// @ts-ignore - Type 'string' is not assignable to type 'undefined'
// Probably because exports.agentUuid is set to undefined and export values were not supposed to be changed
// TODO: This has no effect. Investigate further.
agentOpts.agentUuid = parentProcessAgentUuid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you comment out this line, the tests still work.
The corrected test logic proofs that this is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another PR will come to remove it and to improve the logic in our codebase for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was refactoring the codebase for util, config and logging and these agentOpts file was in my way and then I digged into this, because its very dirty code.

if (uniqueAgentUuids) {
uuid = uuids[pid] = `agent-stub-uuid-${pid}`;
} else {
uuid = 'agent-stub-uuid';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bull tests were false positives.
The agent stub always returned "agent-stub-uuid" for ANY registered process.

The test asserted that the spans from the bull child process (bull forks a process for jobs), have this uuid for span.f.h (agentOpts.agentUuid). And this agentUuid is set to its parent process uuid (see immediate) -> but any process uses the hardcoded UUID from the agent stub "agent-stub-uuid"! So you don't know if its the actual parent uuid or the child uuid.

Each process gets now its own uuid.
I have updated the tests to proof that the INSTANA_AGENT_UUID has no effect and is not used.

if (f.startsWith('file-created-by-job') && f.endsWith('.json')) {
fs.unlinkSync(path.join(__dirname, f));
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup json files before starting. This was missing.


globalAgent.setUpCleanUpHooks();
const agentControls = globalAgent.instance;
await customAgentControls.startAgent({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom agent with using the new uniqueAgentUuids option.

// 2 x http exit
// 2 x redis
// 4 x otel (read + write for the job files)
spanLength: 13,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is more otel spans now because we read + write more to the the file system. See util.js.

fileCreatedByJob = path.join(__dirname, 'file-created-by-job.json');
}

jobData.pid = process.pid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign pid to job data file to get access to the forked bull child pids.

return originalProcessJob.apply(ctx, originalArgs);
}

// TODO: The entry is CREATED BEFORE the child process is forked. Its created ON THE receiver process.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super weird. I won't look into it, but its good to know this. I guess the decision was made because there was no way to create the entry on the child process - but not sure.

@kirrg001 kirrg001 marked this pull request as ready for review September 16, 2025 13:50
@kirrg001 kirrg001 requested a review from a team as a code owner September 16, 2025 13:50

if (jobData.data.bulkIndex) {
fileCreatedByJob = path.join(__dirname, `file-created-by-job-${jobData.data.bulkIndex}.json`);
} else if (jobData.opts.jobId?.includes('repeat')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some logic to store the job files for repeat case. Not really interesting

log(`Job named ${jobName} and concurrent`);
currentTypeArgs.unshift(jobName, NUMBER_OF_PROCESSES);
} else if (jobName && !isConcurrent) {
// You cannot set name + concurrency at the same time. The concurrency is ignored in that case.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests used BULL_CONCURRENCY_ENABLED=true but it had no effect because of ^ 😭

log(`Job named ${jobName}, not concurrent`);
currentTypeArgs.unshift(jobName);
} else if (!jobName && isConcurrent) {
// TODO: We don't have a test for this yet.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test cases for concurrency - that means one job two processes.

BULL_RECEIVE_TYPE: receiveMethod,
BULL_JOB_NAME: 'steve',
BULL_JOB_NAME_ENABLED: 'true',
BULL_CONCURRENCY_ENABLED: 'true'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@aryamohanan aryamohanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-approving..

@abhilash-sivan
Copy link
Contributor

The tests are not exited properly. Please ensure before merging.

response,
apiPath,
spanLength: 17,
spanLength: 19,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirrg001
Copy link
Contributor Author

kirrg001 commented Sep 17, 2025

The tests are not exited properly. Please ensure before merging.

👍 Custom Agent was not stopped

@kirrg001 kirrg001 merged commit 8cc9b54 into main Sep 17, 2025
1 check passed
@instanacd instanacd deleted the test-bull-bug branch November 17, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants