mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-20 16:07:11 +08:00
test(ql3): prove legacy env replay across promotion
This commit is contained in:
@@ -379,6 +379,11 @@ const {
|
||||
persistCancellationDispatchHaFixture,
|
||||
verifyPromotedCancellationDispatchHaFixture,
|
||||
} = require('./ql3-postgres-ha-cancellation-dispatch-fixture.cjs');
|
||||
const {
|
||||
clusterLegacyEnvMigrationApplicationFacts,
|
||||
persistClusterLegacyEnvMigrationApplicationBeforePromotion,
|
||||
verifyPromotedClusterLegacyEnvMigrationApplication,
|
||||
} = require('./ql3-postgres-ha-legacy-env-application-fixture.cjs');
|
||||
const {
|
||||
activateInstall,
|
||||
pluginPackageTaskReconciliationFixture,
|
||||
@@ -11405,6 +11410,7 @@ async function main(argv = process.argv.slice(2)) {
|
||||
let runAttemptLogRetention;
|
||||
let manualRunRetry;
|
||||
let cancellationDispatch;
|
||||
let clusterLegacyEnvMigrationApplication;
|
||||
const startedAt = performance.now();
|
||||
const timeline = [];
|
||||
let report;
|
||||
@@ -11920,6 +11926,43 @@ async function main(argv = process.argv.slice(2)) {
|
||||
state: 'synchronous_remote_apply_ready',
|
||||
atMs: Number((performance.now() - startedAt).toFixed(3)),
|
||||
});
|
||||
const legacyEnvAutomationDatabase = await databaseOpener(
|
||||
'automation-manager',
|
||||
databaseUrl(
|
||||
AUTOMATION_MANAGER_USER,
|
||||
AUTOMATION_MANAGER_PASSWORD,
|
||||
primaryPort,
|
||||
),
|
||||
'ql3-ha-legacy-env-application-primary',
|
||||
)();
|
||||
try {
|
||||
clusterLegacyEnvMigrationApplication =
|
||||
await persistClusterLegacyEnvMigrationApplicationBeforePromotion({
|
||||
migrationPool: primaryDatabase.pool,
|
||||
automationPool: legacyEnvAutomationDatabase.pool,
|
||||
});
|
||||
} finally {
|
||||
await legacyEnvAutomationDatabase.close();
|
||||
}
|
||||
const replicatedLegacyEnvApplication = await waitFor(async () => {
|
||||
const facts = await clusterLegacyEnvMigrationApplicationFacts(
|
||||
standbyDatabase.pool,
|
||||
clusterLegacyEnvMigrationApplication.fixture,
|
||||
);
|
||||
return JSON.stringify(facts) ===
|
||||
JSON.stringify(
|
||||
clusterLegacyEnvMigrationApplication.report.primaryBeforePromotion,
|
||||
)
|
||||
? facts
|
||||
: null;
|
||||
}, 'Cluster Legacy Env migration application WAL replay');
|
||||
clusterLegacyEnvMigrationApplication.report.standbyBeforePromotion =
|
||||
replicatedLegacyEnvApplication;
|
||||
clusterLegacyEnvMigrationApplication.report.replicatedBeforePromotion = true;
|
||||
timeline.push({
|
||||
state: 'cluster_legacy_env_application_replicated',
|
||||
atMs: Number((performance.now() - startedAt).toFixed(3)),
|
||||
});
|
||||
await waitFor(async () => {
|
||||
const replicated = await copilotFailureDiagnosisAdmissionFacts(
|
||||
standbyDatabase.pool,
|
||||
@@ -13465,6 +13508,11 @@ async function main(argv = process.argv.slice(2)) {
|
||||
database: recoveredAutomationManagerDatabase,
|
||||
report: automationManagementInspection,
|
||||
});
|
||||
await verifyPromotedClusterLegacyEnvMigrationApplication({
|
||||
automationPool: recoveredAutomationManagerDatabase.pool,
|
||||
promotedPool: promotedDatabase.pool,
|
||||
evidence: clusterLegacyEnvMigrationApplication,
|
||||
});
|
||||
} finally {
|
||||
await recoveredAutomationManagerDatabase.close();
|
||||
}
|
||||
@@ -13472,6 +13520,10 @@ async function main(argv = process.argv.slice(2)) {
|
||||
state: 'automation_management_inspection_survived_promotion',
|
||||
atMs: Number((performance.now() - startedAt).toFixed(3)),
|
||||
});
|
||||
timeline.push({
|
||||
state: 'cluster_legacy_env_application_replayed_after_promotion',
|
||||
atMs: Number((performance.now() - startedAt).toFixed(3)),
|
||||
});
|
||||
await verifyPluginPackageQuarantineAfterPromotion({
|
||||
promotedPort: standbyPort,
|
||||
promotedDatabase,
|
||||
@@ -13954,6 +14006,8 @@ async function main(argv = process.argv.slice(2)) {
|
||||
approvalIdentityKeysetLedger,
|
||||
runManagementIdentityKeysetLedger,
|
||||
automationManagementInspection,
|
||||
clusterLegacyEnvMigrationApplication:
|
||||
clusterLegacyEnvMigrationApplication.report,
|
||||
pluginPackageLifecycle: pluginPackageLifecycle.report,
|
||||
pluginPackageQuarantine: pluginPackageQuarantine.report,
|
||||
pluginPackagePromptExecution: pluginPackageQuarantine.promptExecution,
|
||||
@@ -14312,6 +14366,30 @@ async function main(argv = process.argv.slice(2)) {
|
||||
.successfulReadAuditCount === 4 &&
|
||||
automationManagementInspection.afterPromotion.taskRevision === 1 &&
|
||||
automationManagementInspection.afterPromotion.triggerRevision === 1,
|
||||
clusterLegacyEnvMigrationApplicationExactlyReplaysAfterPromotion:
|
||||
clusterLegacyEnvMigrationApplication.report
|
||||
.replicatedBeforePromotion === true &&
|
||||
clusterLegacyEnvMigrationApplication.report
|
||||
.exactReplayAfterPromotion === true &&
|
||||
clusterLegacyEnvMigrationApplication.report.replayStatus ===
|
||||
'existing' &&
|
||||
clusterLegacyEnvMigrationApplication.report
|
||||
.mutationStreamsOpenedAfterPromotion === 0 &&
|
||||
clusterLegacyEnvMigrationApplication.report
|
||||
.durableRowsAddedByReplay === 0 &&
|
||||
JSON.stringify(
|
||||
clusterLegacyEnvMigrationApplication.report.primaryBeforePromotion,
|
||||
) ===
|
||||
JSON.stringify(
|
||||
clusterLegacyEnvMigrationApplication.report
|
||||
.standbyBeforePromotion,
|
||||
) &&
|
||||
JSON.stringify(
|
||||
clusterLegacyEnvMigrationApplication.report.primaryBeforePromotion,
|
||||
) ===
|
||||
JSON.stringify(
|
||||
clusterLegacyEnvMigrationApplication.report.promotedAfterReplay,
|
||||
),
|
||||
pluginPackageLifecycleCommitResponseLossConvergesExactlyOnce: true,
|
||||
pluginPackageLifecycleRunAndToolFencesTransitionAtomically: true,
|
||||
pluginPackageAutomationPublicationTransitionsAtomically:
|
||||
|
||||
@@ -15,11 +15,47 @@ const REQUIRED_TIMELINE_STATES = Object.freeze([
|
||||
'primary_ready',
|
||||
'standby_streaming',
|
||||
'synchronous_remote_apply_ready',
|
||||
'cluster_legacy_env_application_replicated',
|
||||
'replication_partition_and_promotion_guard_verified',
|
||||
'old_primary_fenced_and_admission_withdrawn',
|
||||
'cluster_legacy_env_application_replayed_after_promotion',
|
||||
'standby_promoted_old_primary_rejoined_endpoint_switched',
|
||||
'two_fresh_control_replicas_ready',
|
||||
]);
|
||||
const LEGACY_ENV_APPLICATION_FACT_KEYS = Object.freeze(
|
||||
[
|
||||
'executionContentDigest',
|
||||
'planRows',
|
||||
'receiptDigest',
|
||||
'receiptRows',
|
||||
'scheduleClaimVersion',
|
||||
'scheduleRevision',
|
||||
'scheduleStateVersion',
|
||||
'taskContentDigest',
|
||||
'taskCount',
|
||||
'taskItemRows',
|
||||
'taskRevision',
|
||||
'triggerContentDigest',
|
||||
'triggerCount',
|
||||
'triggerItemRows',
|
||||
'triggerRevision',
|
||||
'triggerTaskContentDigest',
|
||||
'triggerTaskRevision',
|
||||
].sort(),
|
||||
);
|
||||
const LEGACY_ENV_APPLICATION_KEYS = Object.freeze(
|
||||
[
|
||||
'contentFree',
|
||||
'durableRowsAddedByReplay',
|
||||
'exactReplayAfterPromotion',
|
||||
'mutationStreamsOpenedAfterPromotion',
|
||||
'primaryBeforePromotion',
|
||||
'promotedAfterReplay',
|
||||
'replayStatus',
|
||||
'replicatedBeforePromotion',
|
||||
'standbyBeforePromotion',
|
||||
].sort(),
|
||||
);
|
||||
const FORBIDDEN_MATERIAL = Object.freeze([
|
||||
'postgresql://',
|
||||
'ql3_migration_test',
|
||||
@@ -36,6 +72,8 @@ const FORBIDDEN_MATERIAL = Object.freeze([
|
||||
'ql3_worker_credential_executor_test',
|
||||
'ql3_worker_ingress_test',
|
||||
'ql3w_',
|
||||
'qlsecret:v1:',
|
||||
'ha-legacy-env-bundle-private',
|
||||
]);
|
||||
|
||||
function isObject(value) {
|
||||
@@ -250,6 +288,86 @@ function auditPostgresHaEvidence(report) {
|
||||
'UNCOMMITTED_WRITE_SURVIVED',
|
||||
);
|
||||
|
||||
const legacyEnvApplication = report.clusterLegacyEnvMigrationApplication;
|
||||
add(
|
||||
isObject(legacyEnvApplication),
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_EVIDENCE_MISSING',
|
||||
);
|
||||
if (isObject(legacyEnvApplication)) {
|
||||
add(
|
||||
JSON.stringify(Object.keys(legacyEnvApplication).sort()) ===
|
||||
JSON.stringify(LEGACY_ENV_APPLICATION_KEYS),
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_EVIDENCE_WIDENED',
|
||||
);
|
||||
add(
|
||||
legacyEnvApplication.replicatedBeforePromotion === true,
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_NOT_REPLICATED',
|
||||
);
|
||||
add(
|
||||
legacyEnvApplication.exactReplayAfterPromotion === true &&
|
||||
legacyEnvApplication.replayStatus === 'existing',
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_REPLAY_INVALID',
|
||||
);
|
||||
add(
|
||||
legacyEnvApplication.mutationStreamsOpenedAfterPromotion === 0 &&
|
||||
legacyEnvApplication.durableRowsAddedByReplay === 0,
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_REPLAY_SIDE_EFFECT',
|
||||
);
|
||||
add(
|
||||
legacyEnvApplication.contentFree === true,
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_EVIDENCE_NOT_CONTENT_FREE',
|
||||
);
|
||||
const factSets = [
|
||||
legacyEnvApplication.primaryBeforePromotion,
|
||||
legacyEnvApplication.standbyBeforePromotion,
|
||||
legacyEnvApplication.promotedAfterReplay,
|
||||
];
|
||||
for (const facts of factSets) {
|
||||
add(isObject(facts), 'CLUSTER_LEGACY_ENV_APPLICATION_FACTS_INVALID');
|
||||
if (!isObject(facts)) continue;
|
||||
add(
|
||||
JSON.stringify(Object.keys(facts).sort()) ===
|
||||
JSON.stringify(LEGACY_ENV_APPLICATION_FACT_KEYS),
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_FACTS_WIDENED',
|
||||
);
|
||||
add(
|
||||
facts.planRows === 1 &&
|
||||
facts.receiptRows === 1 &&
|
||||
facts.taskItemRows === 1 &&
|
||||
facts.triggerItemRows === 1 &&
|
||||
facts.taskCount === 1 &&
|
||||
facts.triggerCount === 1 &&
|
||||
facts.taskRevision === 3 &&
|
||||
facts.triggerRevision === 2 &&
|
||||
facts.triggerTaskRevision === 3 &&
|
||||
facts.scheduleRevision === 2 &&
|
||||
facts.scheduleStateVersion === 1 &&
|
||||
facts.scheduleClaimVersion === 1,
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_FACTS_DRIFTED',
|
||||
);
|
||||
for (const key of [
|
||||
'receiptDigest',
|
||||
'taskContentDigest',
|
||||
'executionContentDigest',
|
||||
'triggerContentDigest',
|
||||
'triggerTaskContentDigest',
|
||||
]) {
|
||||
add(
|
||||
typeof facts[key] === 'string' && SHA256_PATTERN.test(facts[key]),
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_DIGEST_INVALID',
|
||||
);
|
||||
}
|
||||
}
|
||||
add(
|
||||
factSets.every(
|
||||
(facts) =>
|
||||
isObject(facts) &&
|
||||
JSON.stringify(facts) === JSON.stringify(factSets[0]),
|
||||
),
|
||||
'CLUSTER_LEGACY_ENV_APPLICATION_FACTS_NOT_EXACT',
|
||||
);
|
||||
}
|
||||
|
||||
const gates = report.gates;
|
||||
add(isObject(gates), 'GATES_MISSING');
|
||||
if (isObject(gates)) {
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const {
|
||||
PostgresTaskDefinitionRepository,
|
||||
PostgresTriggerRepository,
|
||||
} = require('../packages/ql3-cluster-postgres/dist/entrypoints/admin.js');
|
||||
const {
|
||||
PostgresClusterLegacyEnvMigrationPlanRepository,
|
||||
} = require('../packages/ql3-cluster-postgres/dist/reconciliation/clusterLegacyEnvMigrationPlanRepository.js');
|
||||
const {
|
||||
PostgresClusterLegacyEnvMigrationApplicationRepository,
|
||||
} = require('../packages/ql3-cluster-postgres/dist/reconciliation/clusterLegacyEnvMigrationApplicationRepository.js');
|
||||
const {
|
||||
createClusterLegacyEnvMigrationTaskMutationSetDigester,
|
||||
createClusterLegacyEnvMigrationTriggerMutationSetDigester,
|
||||
} = require('../packages/ql3-runtime-core/dist/migration/clusterLegacyEnvMigrationApplication.js');
|
||||
const {
|
||||
createSecretRef,
|
||||
} = require('../packages/ql3-runtime-core/dist/secret/secretReference.js');
|
||||
|
||||
const FIXTURE = Object.freeze({
|
||||
projectId: 'ha-legacy-env-application',
|
||||
taskId: 'ha legacy env task',
|
||||
triggerId: 'ha legacy env trigger',
|
||||
planId: 'ha-legacy-env-plan',
|
||||
planMutationId: '819f7900-0000-4000-8000-000000000001',
|
||||
applicationId: 'ha-legacy-env-application-receipt',
|
||||
applicationMutationId: '819f7900-0000-4000-8000-000000000002',
|
||||
taskCreateMutationId: '819f7900-0000-4000-8000-000000000003',
|
||||
triggerCreateMutationId: '819f7900-0000-4000-8000-000000000004',
|
||||
taskAdvanceMutationId: '819f7900-0000-4000-8000-000000000005',
|
||||
taskApplicationMutationId: '819f7900-0000-4000-8000-000000000006',
|
||||
triggerApplicationMutationId: '819f7900-0000-4000-8000-000000000007',
|
||||
privateBundleName: 'ha-legacy-env-bundle-private',
|
||||
});
|
||||
|
||||
async function clusterLegacyEnvMigrationApplicationFacts(pool, fixture) {
|
||||
const result = await pool.query(
|
||||
`SELECT
|
||||
receipt.receipt_digest AS "receiptDigest",
|
||||
receipt.task_count AS "taskCount",
|
||||
receipt.trigger_count AS "triggerCount",
|
||||
task_item.revision AS "taskRevision",
|
||||
task_item.content_digest AS "taskContentDigest",
|
||||
task_item.execution_content_digest AS "executionContentDigest",
|
||||
trigger_item.revision AS "triggerRevision",
|
||||
trigger_item.content_digest AS "triggerContentDigest",
|
||||
trigger_item.task_revision AS "triggerTaskRevision",
|
||||
trigger_item.task_content_digest AS "triggerTaskContentDigest",
|
||||
schedule.trigger_revision AS "scheduleRevision",
|
||||
schedule.state_version AS "scheduleStateVersion",
|
||||
schedule.claim_version AS "scheduleClaimVersion",
|
||||
(SELECT count(*)::integer
|
||||
FROM "ql3"."cluster_legacy_env_migration_plans" AS plan
|
||||
WHERE plan.plan_id = receipt.plan_id) AS "planRows",
|
||||
(SELECT count(*)::integer
|
||||
FROM "ql3"."cluster_legacy_env_migration_application_receipts" AS stored
|
||||
WHERE stored.application_id = receipt.application_id) AS "receiptRows",
|
||||
(SELECT count(*)::integer
|
||||
FROM "ql3"."cluster_legacy_env_migration_application_tasks" AS item
|
||||
WHERE item.application_id = receipt.application_id) AS "taskItemRows",
|
||||
(SELECT count(*)::integer
|
||||
FROM "ql3"."cluster_legacy_env_migration_application_triggers" AS item
|
||||
WHERE item.application_id = receipt.application_id) AS "triggerItemRows"
|
||||
FROM "ql3"."cluster_legacy_env_migration_application_receipts" AS receipt
|
||||
JOIN "ql3"."cluster_legacy_env_migration_application_tasks" AS task_item
|
||||
ON task_item.application_id = receipt.application_id
|
||||
AND task_item.ordinal = 0
|
||||
JOIN "ql3"."cluster_legacy_env_migration_application_triggers" AS trigger_item
|
||||
ON trigger_item.application_id = receipt.application_id
|
||||
AND trigger_item.ordinal = 0
|
||||
JOIN "ql3"."trigger_schedules" AS schedule
|
||||
ON schedule.project_id = trigger_item.project_id
|
||||
AND schedule.trigger_id = trigger_item.trigger_id
|
||||
WHERE receipt.application_id = $1`,
|
||||
[fixture.applicationId],
|
||||
);
|
||||
assert.equal(result.rowCount, 1);
|
||||
return Object.freeze({ ...result.rows[0] });
|
||||
}
|
||||
|
||||
function assertExpectedFacts(facts) {
|
||||
assert.equal(facts.planRows, 1);
|
||||
assert.equal(facts.receiptRows, 1);
|
||||
assert.equal(facts.taskItemRows, 1);
|
||||
assert.equal(facts.triggerItemRows, 1);
|
||||
assert.equal(facts.taskCount, 1);
|
||||
assert.equal(facts.triggerCount, 1);
|
||||
assert.equal(facts.taskRevision, 3);
|
||||
assert.equal(facts.triggerRevision, 2);
|
||||
assert.equal(facts.triggerTaskRevision, 3);
|
||||
assert.equal(facts.scheduleRevision, 2);
|
||||
assert.equal(facts.scheduleStateVersion, 1);
|
||||
assert.equal(facts.scheduleClaimVersion, 1);
|
||||
for (const digest of [
|
||||
facts.receiptDigest,
|
||||
facts.taskContentDigest,
|
||||
facts.executionContentDigest,
|
||||
facts.triggerContentDigest,
|
||||
facts.triggerTaskContentDigest,
|
||||
]) {
|
||||
assert.match(digest, /^[0-9a-f]{64}$/);
|
||||
}
|
||||
}
|
||||
|
||||
async function persistClusterLegacyEnvMigrationApplicationBeforePromotion(
|
||||
options,
|
||||
) {
|
||||
const { migrationPool, automationPool } = options;
|
||||
const observed = await migrationPool.query(
|
||||
`SELECT floor(extract(epoch FROM clock_timestamp()) * 1000)::bigint
|
||||
AS "observedAtMs"`,
|
||||
);
|
||||
const occurredAtMs = Number(observed.rows[0].observedAtMs) - 1_000;
|
||||
await migrationPool.query(
|
||||
`INSERT INTO "ql3"."projects" (
|
||||
id, name, slug, status, version, created_at_ms, updated_at_ms
|
||||
) VALUES ($1, 'HA Legacy Env application', $1, 'active', 1, $2, $2)`,
|
||||
[FIXTURE.projectId, occurredAtMs],
|
||||
);
|
||||
|
||||
const tasks = new PostgresTaskDefinitionRepository(migrationPool);
|
||||
const triggers = new PostgresTriggerRepository(migrationPool);
|
||||
const initialTask = (
|
||||
await tasks.appendTaskDefinitionRevision({
|
||||
projectId: FIXTURE.projectId,
|
||||
taskId: FIXTURE.taskId,
|
||||
expectedRevision: null,
|
||||
mutationId: FIXTURE.taskCreateMutationId,
|
||||
name: 'HA Legacy Env command',
|
||||
description: 'promotion replay fixture',
|
||||
kind: 'command',
|
||||
spec: {
|
||||
schema: 'qinglong/command@v1',
|
||||
config: {
|
||||
command: { kind: 'argv', file: '/bin/echo', args: ['ha'] },
|
||||
timeoutMs: 30_000,
|
||||
},
|
||||
},
|
||||
labels: { 'qinglong.io/source': 'ha-contract' },
|
||||
enabled: true,
|
||||
occurredAtMs,
|
||||
})
|
||||
).definition;
|
||||
const initialTrigger = (
|
||||
await triggers.appendTriggerRevision({
|
||||
projectId: FIXTURE.projectId,
|
||||
triggerId: FIXTURE.triggerId,
|
||||
expectedRevision: null,
|
||||
mutationId: FIXTURE.triggerCreateMutationId,
|
||||
taskId: FIXTURE.taskId,
|
||||
taskRevision: initialTask.revision,
|
||||
taskContentDigest: initialTask.contentDigest,
|
||||
spec: {
|
||||
schema: 'qinglong/cron@v1',
|
||||
config: {
|
||||
expression: '* * * * *',
|
||||
timezone: 'UTC',
|
||||
misfirePolicy: 'skip',
|
||||
},
|
||||
},
|
||||
enabled: false,
|
||||
occurredAtMs: occurredAtMs + 1,
|
||||
})
|
||||
).trigger;
|
||||
const currentTask = (
|
||||
await tasks.appendTaskDefinitionRevision({
|
||||
projectId: FIXTURE.projectId,
|
||||
taskId: FIXTURE.taskId,
|
||||
expectedRevision: initialTask.revision,
|
||||
mutationId: FIXTURE.taskAdvanceMutationId,
|
||||
name: initialTask.name,
|
||||
description: initialTask.description,
|
||||
kind: initialTask.kind,
|
||||
spec: initialTask.spec,
|
||||
labels: initialTask.labels,
|
||||
enabled: initialTask.enabled,
|
||||
occurredAtMs: occurredAtMs + 2,
|
||||
})
|
||||
).definition;
|
||||
|
||||
const taskMutations = Object.freeze([
|
||||
Object.freeze({
|
||||
ordinal: 0,
|
||||
taskId: FIXTURE.taskId,
|
||||
previousRevision: currentTask.revision,
|
||||
previousContentDigest: currentTask.contentDigest,
|
||||
mutationId: FIXTURE.taskApplicationMutationId,
|
||||
}),
|
||||
]);
|
||||
const triggerMutations = Object.freeze([
|
||||
Object.freeze({
|
||||
ordinal: 0,
|
||||
triggerId: FIXTURE.triggerId,
|
||||
taskId: FIXTURE.taskId,
|
||||
previousRevision: initialTrigger.revision,
|
||||
previousContentDigest: initialTrigger.contentDigest,
|
||||
previousTaskRevision: initialTask.revision,
|
||||
previousTaskContentDigest: initialTask.contentDigest,
|
||||
mutationId: FIXTURE.triggerApplicationMutationId,
|
||||
}),
|
||||
]);
|
||||
const taskDigester = createClusterLegacyEnvMigrationTaskMutationSetDigester();
|
||||
taskDigester.update(taskMutations[0]);
|
||||
const taskSet = taskDigester.finish();
|
||||
const triggerDigester =
|
||||
createClusterLegacyEnvMigrationTriggerMutationSetDigester();
|
||||
triggerDigester.update(triggerMutations[0]);
|
||||
const triggerSet = triggerDigester.finish();
|
||||
const secretRef = createSecretRef({
|
||||
projectId: FIXTURE.projectId,
|
||||
name: FIXTURE.privateBundleName,
|
||||
version: 1,
|
||||
});
|
||||
const plan = (
|
||||
await new PostgresClusterLegacyEnvMigrationPlanRepository(
|
||||
automationPool,
|
||||
).publish({
|
||||
planId: FIXTURE.planId,
|
||||
mutationId: FIXTURE.planMutationId,
|
||||
projectId: FIXTURE.projectId,
|
||||
source: {
|
||||
reconciliationBundleDigest: '1'.repeat(64),
|
||||
decisionDigest: '2'.repeat(64),
|
||||
candidateSetDigest: '3'.repeat(64),
|
||||
sourceRowCount: 1,
|
||||
activeRowCount: 1,
|
||||
disabledRowCount: 0,
|
||||
effectiveBindingCount: 1,
|
||||
},
|
||||
target: {
|
||||
secretRef,
|
||||
taskRevisionSetDigest: taskSet.revisionSetDigest,
|
||||
triggerRevisionSetDigest: triggerSet.revisionSetDigest,
|
||||
taskCount: taskSet.count,
|
||||
triggerCount: triggerSet.count,
|
||||
totalEffectiveBytes: 128,
|
||||
},
|
||||
})
|
||||
).plan;
|
||||
const intent = Object.freeze({
|
||||
applicationId: FIXTURE.applicationId,
|
||||
mutationId: FIXTURE.applicationMutationId,
|
||||
projectId: FIXTURE.projectId,
|
||||
planId: FIXTURE.planId,
|
||||
planDigest: plan.planDigest,
|
||||
taskMutationSetDigest: taskSet.mutationSetDigest,
|
||||
triggerMutationSetDigest: triggerSet.mutationSetDigest,
|
||||
});
|
||||
let taskStreamOpenCount = 0;
|
||||
let triggerStreamOpenCount = 0;
|
||||
const applications =
|
||||
new PostgresClusterLegacyEnvMigrationApplicationRepository(automationPool);
|
||||
const applied = await applications.apply(intent, {
|
||||
taskMutations() {
|
||||
taskStreamOpenCount += 1;
|
||||
return taskMutations;
|
||||
},
|
||||
triggerMutations() {
|
||||
triggerStreamOpenCount += 1;
|
||||
return triggerMutations;
|
||||
},
|
||||
});
|
||||
assert.equal(applied.status, 'applied');
|
||||
assert.equal(taskStreamOpenCount, 1);
|
||||
assert.equal(triggerStreamOpenCount, 1);
|
||||
const primaryBeforePromotion =
|
||||
await clusterLegacyEnvMigrationApplicationFacts(migrationPool, FIXTURE);
|
||||
assertExpectedFacts(primaryBeforePromotion);
|
||||
return {
|
||||
fixture: Object.freeze({
|
||||
...FIXTURE,
|
||||
intent,
|
||||
receipt: applied.receipt,
|
||||
}),
|
||||
report: {
|
||||
primaryBeforePromotion,
|
||||
standbyBeforePromotion: null,
|
||||
promotedAfterReplay: null,
|
||||
replicatedBeforePromotion: false,
|
||||
exactReplayAfterPromotion: false,
|
||||
replayStatus: null,
|
||||
mutationStreamsOpenedAfterPromotion: null,
|
||||
durableRowsAddedByReplay: null,
|
||||
contentFree: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function verifyPromotedClusterLegacyEnvMigrationApplication(options) {
|
||||
const { automationPool, promotedPool, evidence } = options;
|
||||
let mutationStreamsOpened = 0;
|
||||
const applications =
|
||||
new PostgresClusterLegacyEnvMigrationApplicationRepository(automationPool);
|
||||
const beforeReplay = await clusterLegacyEnvMigrationApplicationFacts(
|
||||
promotedPool,
|
||||
evidence.fixture,
|
||||
);
|
||||
assert.deepEqual(beforeReplay, evidence.report.primaryBeforePromotion);
|
||||
const replay = await applications.apply(evidence.fixture.intent, {
|
||||
taskMutations() {
|
||||
mutationStreamsOpened += 1;
|
||||
throw new Error('exact replay must not reopen Task mutations');
|
||||
},
|
||||
triggerMutations() {
|
||||
mutationStreamsOpened += 1;
|
||||
throw new Error('exact replay must not reopen Trigger mutations');
|
||||
},
|
||||
});
|
||||
assert.equal(replay.status, 'existing');
|
||||
assert.deepEqual(replay.receipt, evidence.fixture.receipt);
|
||||
const promotedAfterReplay = await clusterLegacyEnvMigrationApplicationFacts(
|
||||
promotedPool,
|
||||
evidence.fixture,
|
||||
);
|
||||
assertExpectedFacts(promotedAfterReplay);
|
||||
assert.deepEqual(promotedAfterReplay, beforeReplay);
|
||||
evidence.report.promotedAfterReplay = promotedAfterReplay;
|
||||
evidence.report.exactReplayAfterPromotion = true;
|
||||
evidence.report.replayStatus = replay.status;
|
||||
evidence.report.mutationStreamsOpenedAfterPromotion = mutationStreamsOpened;
|
||||
evidence.report.durableRowsAddedByReplay =
|
||||
promotedAfterReplay.receiptRows - beforeReplay.receiptRows;
|
||||
return evidence.report;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clusterLegacyEnvMigrationApplicationFacts,
|
||||
persistClusterLegacyEnvMigrationApplicationBeforePromotion,
|
||||
verifyPromotedClusterLegacyEnvMigrationApplication,
|
||||
};
|
||||
Reference in New Issue
Block a user