Skip to content

Commit

Permalink
fix(core): Fix isLeader check in WaitTracker constructor (#9100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored and netroy committed Apr 11, 2024
1 parent 3992ae7 commit 549e8f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
15 changes: 9 additions & 6 deletions packages/cli/src/WaitTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/services/orchestration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ export class OrchestrationService {
);
}

get isSingleMainSetup() {
return !this.isMultiMainSetupEnabled;
}

redisPublisher: RedisServicePubSubPublisher;

get instanceId() {
return config.getEnv('redis.queueModeId');
}

/**
* 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';
Expand Down
17 changes: 13 additions & 4 deletions packages/cli/test/unit/WaitTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>({
Expand Down Expand Up @@ -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() }),
});

Expand All @@ -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() }),
});

Expand Down

0 comments on commit 549e8f7

Please sign in to comment.