feat(events): add idempotent Kafka event consumer runtime
This commit is contained in:
1 parent
565ef8d4f5
commit
3adb0ef9e4
47 files changed
+5018
-105
No files matched your search
@@ -24,13 +24,16 @@ const (
|
||||
identityMigrationVersion = 2
|
||||
// policyMigrationVersion creates policyTableNames and policyFunctionNames.
|
||||
policyMigrationVersion = 3
|
||||
// consumerMigrationVersion creates consumerTableNames.
|
||||
consumerMigrationVersion = 5
|
||||
)
|
||||
|
||||
var (
|
||||
// Tables created by 00001, 00002, and 00003.
|
||||
// Tables created by 00001, 00002, 00003, and 00005.
|
||||
outboxTables = []string{"outbox_events"}
|
||||
identityTableNames = []string{"users", "email_tokens", "sessions"}
|
||||
policyTableNames = []string{"policy_versions"}
|
||||
consumerTableNames = []string{"consumer_processed_events", "consumer_dead_letters"}
|
||||
// Trigger functions created by 00003.
|
||||
policyFunctionNames = []string{"policy_versions_refuse_change()", "policy_versions_stamp_creation()"}
|
||||
)
|
||||
@@ -61,8 +64,9 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertTablesExist(ctx, t, pool, true, identityTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, policyTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, policyFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, consumerTableNames...)
|
||||
|
||||
identityRolledBack, policyRolledBack := false, false
|
||||
identityRolledBack, policyRolledBack, consumerRolledBack := false, false, false
|
||||
for rolledBack := 0; ; rolledBack++ {
|
||||
result, err := migrator.DownOne(ctx)
|
||||
if errors.Is(err, postgresadapter.ErrNoMigrationToRollBack) {
|
||||
@@ -74,6 +78,12 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("DownOne() after %d rollbacks error = %v", rolledBack, err)
|
||||
}
|
||||
if result.Version == consumerMigrationVersion {
|
||||
// The consumer migration removes only its own tables.
|
||||
assertTablesExist(ctx, t, pool, false, consumerTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, outboxTables...)
|
||||
consumerRolledBack = true
|
||||
}
|
||||
if result.Version == policyMigrationVersion {
|
||||
// The policy migration rolls back its table, triggers, and
|
||||
// function and leaves the identity tables.
|
||||
@@ -90,8 +100,8 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
identityRolledBack = true
|
||||
}
|
||||
}
|
||||
if !identityRolledBack || !policyRolledBack {
|
||||
t.Fatalf("migrations %d and %d were not both rolled back", identityMigrationVersion, policyMigrationVersion)
|
||||
if !identityRolledBack || !policyRolledBack || !consumerRolledBack {
|
||||
t.Fatalf("migrations %d, %d, and %d were not all rolled back", identityMigrationVersion, policyMigrationVersion, consumerMigrationVersion)
|
||||
}
|
||||
assertTablesExist(ctx, t, pool, false, outboxTables...)
|
||||
assertTablesExist(ctx, t, pool, false, identityTableNames...)
|
||||
@@ -130,6 +140,7 @@ func TestPostgresMigrations(t *testing.T) {
|
||||
assertTablesExist(ctx, t, pool, true, identityTableNames...)
|
||||
assertTablesExist(ctx, t, pool, true, policyTableNames...)
|
||||
assertFunctionsExist(ctx, t, pool, true, policyFunctionNames...)
|
||||
assertTablesExist(ctx, t, pool, true, consumerTableNames...)
|
||||
assertAllApplied(ctx, t, migrator, total)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user