-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ChangesCheckerConsole: Start exactly matching job or all partially ma…
…tching jobs (#2144) Previously, the first job with a partially matching content scope was started. Doing so could lead to problems when multiple jobs with overlapping content scopes exist. For instance, jobs with the scopes `{ domain: "main", language: "de" }` and `{ domain: "main", language: "en" }` both partially match a change in `{ domain: "main", language: "de" }`. To fix this, we either start a single job if the content scope matches exactly or start all jobs with partially matching content scopes.
- Loading branch information
1 parent
6717682
commit b158e6a
Showing
7 changed files
with
169 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@comet/cms-api": patch | ||
--- | ||
|
||
ChangesCheckerConsole: Start exactly matching job or all partially matching jobs | ||
|
||
Previously, the first job with a partially matching content scope was started. | ||
Doing so could lead to problems when multiple jobs with overlapping content scopes exist. | ||
For instance, jobs with the scopes `{ domain: "main", language: "de" }` and `{ domain: "main", language: "en" }` both partially match a change in `{ domain: "main", language: "de" }`. | ||
To fix this, we either start a single job if the content scope matches exactly or start all jobs with partially matching content scopes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { V1CronJob } from "@kubernetes/client-node"; | ||
import { getRepositoryToken } from "@mikro-orm/nestjs"; | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
|
||
import { KubernetesModule } from "../kubernetes/kubernetes.module"; | ||
import { ACCESS_CONTROL_SERVICE } from "../user-permissions/user-permissions.constants"; | ||
import { BuildTemplatesService } from "./build-templates.service"; | ||
import { CONTENT_SCOPE_ANNOTATION } from "./builds.constants"; | ||
import { BuildsService } from "./builds.service"; | ||
import { ChangesSinceLastBuild } from "./entities/changes-since-last-build.entity"; | ||
|
||
const jobMain = { | ||
metadata: { | ||
name: "main", | ||
annotations: { | ||
[CONTENT_SCOPE_ANNOTATION]: '{"domain":"main"}', | ||
}, | ||
}, | ||
}; | ||
|
||
const jobMainEnglish = { | ||
metadata: { | ||
name: "main-en", | ||
annotations: { | ||
[CONTENT_SCOPE_ANNOTATION]: '{"domain":"main","language":"en"}', | ||
}, | ||
}, | ||
}; | ||
|
||
const jobMainGerman = { | ||
metadata: { | ||
name: "main-de", | ||
annotations: { | ||
[CONTENT_SCOPE_ANNOTATION]: '{"domain":"main","language":"de"}', | ||
}, | ||
}, | ||
}; | ||
|
||
const mockedBuildTemplatesService = { | ||
getAllBuilderCronJobs: jest.fn<Promise<V1CronJob[]>, never[]>().mockResolvedValue([jobMainEnglish, jobMainGerman]), | ||
}; | ||
|
||
describe("BuildsService", () => { | ||
let service: BuildsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [KubernetesModule.register({ helmRelease: "test" })], | ||
providers: [ | ||
BuildsService, | ||
{ provide: getRepositoryToken(ChangesSinceLastBuild), useValue: {} }, | ||
{ provide: BuildTemplatesService, useValue: mockedBuildTemplatesService }, | ||
{ provide: ACCESS_CONTROL_SERVICE, useValue: {} }, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<BuildsService>(BuildsService); | ||
}); | ||
|
||
describe("getBuilderCronJobsToStart", () => { | ||
it("should return single job for exact match", async () => { | ||
await expect(service.getBuilderCronJobsToStart([{ domain: "main", language: "en" }])).resolves.toEqual([jobMainEnglish]); | ||
}); | ||
|
||
it("should return multiple jobs for multiple exact matches", async () => { | ||
await expect( | ||
service.getBuilderCronJobsToStart([ | ||
{ domain: "main", language: "en" }, | ||
{ domain: "main", language: "de" }, | ||
]), | ||
).resolves.toEqual([jobMainEnglish, jobMainGerman]); | ||
}); | ||
|
||
it("should return all partially matching jobs", async () => { | ||
await expect(service.getBuilderCronJobsToStart([{ domain: "main" }])).resolves.toEqual([jobMainEnglish, jobMainGerman]); | ||
|
||
// Multiple content scopes in a single builder cron job. | ||
mockedBuildTemplatesService.getAllBuilderCronJobs.mockResolvedValueOnce([jobMain]); | ||
await expect( | ||
service.getBuilderCronJobsToStart([ | ||
{ domain: "main", language: "en" }, | ||
{ domain: "main", language: "de" }, | ||
]), | ||
).resolves.toEqual([jobMain]); | ||
}); | ||
|
||
it("should throw an error if no job is found", async () => { | ||
await expect(service.getBuilderCronJobsToStart([{ domain: "tertiary" }])).rejects.toThrow( | ||
'Found changes in scope {"domain":"tertiary"} but no matching builder cron job!', | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.