fix(core): Fix isLeader check in WaitTracker constructor (#9100)

This commit is contained in:
Iván Ovejero 2024-04-09 15:50:10 +02:00 committed by GitHub
parent d46635fdb9
commit c2f4d7d796
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 11 deletions

View file

@ -29,15 +29,18 @@ export class WaitTracker {
private readonly workflowRunner: WorkflowRunner,
readonly orchestrationService: OrchestrationService,
) {
const { isLeader, isMultiMainSetupEnabled, multiMainSetup } = orchestrationService;
const { isSingleMainSetup, isLeader, multiMainSetup } = orchestrationService;
if (isSingleMainSetup) {
this.startTracking();
return;
}
if (isLeader) this.startTracking();
if (isMultiMainSetupEnabled) {
multiMainSetup
.on('leader-takeover', () => this.startTracking())
.on('leader-stepdown', () => this.stopTracking());
}
multiMainSetup
.on('leader-takeover', () => this.startTracking())
.on('leader-stepdown', () => this.stopTracking());
}
startTracking() {

View file

@ -33,6 +33,10 @@ export class OrchestrationService {
);
}
get isSingleMainSetup() {
return !this.isMultiMainSetupEnabled;
}
redisPublisher: RedisServicePubSubPublisher;
get instanceId() {
@ -40,7 +44,7 @@ export class OrchestrationService {
}
/**
* Whether this instance is the leader in a multi-main setup. Always `true` in single-main setup.
* Whether this instance is the leader in a multi-main setup. Always `false` in single-main setup.
*/
get isLeader() {
return config.getEnv('multiMainSetup.instanceType') === 'leader';

View file

@ -10,8 +10,7 @@ jest.useFakeTimers();
describe('WaitTracker', () => {
const executionRepository = mock<ExecutionRepository>();
const orchestrationService = mock<OrchestrationService>({
isLeader: true,
isMultiMainSetupEnabled: false,
isSingleMainSetup: true,
});
const execution = mock<IExecutionResponse>({
@ -105,11 +104,21 @@ describe('WaitTracker', () => {
});
});
describe('single-main setup', () => {
it('should start tracking', () => {
executionRepository.getWaitingExecutions.mockResolvedValue([]);
new WaitTracker(mock(), executionRepository, mock(), mock(), orchestrationService);
expect(executionRepository.getWaitingExecutions).toHaveBeenCalledTimes(1);
});
});
describe('multi-main setup', () => {
it('should start tracking if leader', () => {
const orchestrationService = mock<OrchestrationService>({
isLeader: true,
isMultiMainSetupEnabled: true,
isSingleMainSetup: false,
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
});
@ -123,7 +132,7 @@ describe('WaitTracker', () => {
it('should not start tracking if follower', () => {
const orchestrationService = mock<OrchestrationService>({
isLeader: false,
isMultiMainSetupEnabled: true,
isSingleMainSetup: false,
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
});