Skip to content

Commit

Permalink
feat: disable scheduler for tests (#4496)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Aug 15, 2023
1 parent 1eae315 commit 16190dd
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -44,6 +44,7 @@ exports[`should create default config 1`] = `
"user": "unleash",
"version": undefined,
},
"disableScheduler": undefined,
"email": {
"host": undefined,
"port": 587,
Expand Down
1 change: 1 addition & 0 deletions src/lib/create-config.ts
Expand Up @@ -499,6 +499,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
accessControlMaxAge,
prometheusApi,
publicFolder: options.publicFolder,
disableScheduler: options.disableScheduler,
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/server-impl.ts
Expand Up @@ -43,7 +43,9 @@ async function createApp(
const db = createDb(config);
const stores = createStores(config, db);
const services = createServices(stores, config, db);
await scheduleServices(services);
if (!config.disableScheduler) {
await scheduleServices(services);
}

const metricsMonitor = createMetricsMonitor();
const unleashSession = sessionDb(config, db);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/maintenance-service.test.ts
Expand Up @@ -24,7 +24,7 @@ test('Maintenance on should pause scheduler', async () => {
});

test('Maintenance off should resume scheduler', async () => {
const config = createTestConfig();
const config = createTestConfig({ disableScheduler: false });
const schedulerService = new SchedulerService(config.getLogger);
schedulerService.pause();
const maintenanceService = new MaintenanceService(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/maintenance-service.ts
Expand Up @@ -58,7 +58,7 @@ export default class MaintenanceService {
): Promise<void> {
if (setting.enabled) {
this.schedulerService.pause();
} else {
} else if (!this.config.disableScheduler) {
this.schedulerService.resume();
}
return this.settingService.insert(
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/option.ts
Expand Up @@ -118,6 +118,7 @@ export interface IUnleashOptions {
accessControlMaxAge?: number;
prometheusApi?: string;
publicFolder?: string;
disableScheduler?: boolean;
}

export interface IEmailOption {
Expand Down Expand Up @@ -207,4 +208,5 @@ export interface IUnleashConfig {
accessControlMaxAge: number;
prometheusApi?: string;
publicFolder?: string;
disableScheduler?: boolean;
}
1 change: 1 addition & 0 deletions src/test/config/test-config.ts
Expand Up @@ -19,6 +19,7 @@ export function createTestConfig(config?: IUnleashOptions): IUnleashConfig {
server: { secret: 'really-secret' },
session: { db: false },
versionCheck: { enable: false },
disableScheduler: true,
clientFeatureCaching: {
enabled: false,
},
Expand Down
1 change: 1 addition & 0 deletions src/test/e2e/helpers/test-helper.ts
Expand Up @@ -179,6 +179,7 @@ async function createApp(
server: {
unleashUrl: 'http://localhost:4242',
},
disableScheduler: true,
...{
...customOptions,
experimental: {
Expand Down

0 comments on commit 16190dd

Please sign in to comment.