From 2085b98651769d27c9f82edffaf69214b7ab0dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Ma=C5=BEgon?= Date: Mon, 2 May 2022 18:01:04 +0200 Subject: [PATCH 1/2] allow for empty transactions in TestRelationSetAllTypes --- source/logrepl/internal/relationset_test.go | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/source/logrepl/internal/relationset_test.go b/source/logrepl/internal/relationset_test.go index 924c0edc..6e4e69e7 100644 --- a/source/logrepl/internal/relationset_test.go +++ b/source/logrepl/internal/relationset_test.go @@ -54,10 +54,36 @@ func TestRelationSetAllTypes(t *testing.T) { _, messages := setupSubscription(ctx, t, conn.Config().Config, table) insertRowAllTypes(ctx, t, conn, table) - <-messages // skip first message, it's a begin message - rel := (<-messages).(*pglogrepl.RelationMessage) // second message is a relation - ins := (<-messages).(*pglogrepl.InsertMessage) // third one is the insert - <-messages // fourth one is the commit + var rel *pglogrepl.RelationMessage + var ins *pglogrepl.InsertMessage + + // loop through messages and allow for empty transactions to be received + for { + // first message needs to be a begin message + msg := <-messages + if _, ok := msg.(*pglogrepl.BeginMessage); !ok { + t.Fatalf("expected begin message, got %s", msg.Type()) + } + + // second message can be either commit (we can catch empty transactions) + // or relation (that's what we are actually interested in) + msg = <-messages + if _, ok := msg.(*pglogrepl.CommitMessage); ok { + continue // empty transaction, skip it + } + + // not an empty transaction, these have to be the messages we are looking for + rel = msg.(*pglogrepl.RelationMessage) // second message is a relation + ins = (<-messages).(*pglogrepl.InsertMessage) // third one is the insert + + // last one needs to be commit + msg = <-messages + if _, ok := msg.(*pglogrepl.CommitMessage); !ok { + t.Fatalf("expected commit message, got %s", msg.Type()) + } + + break + } rs := NewRelationSet(conn.ConnInfo()) From 11f3bb7fd37aaa1cd31c7fcbe0ef78e62e3d62f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Ma=C5=BEgon?= Date: Mon, 9 May 2022 18:17:34 +0200 Subject: [PATCH 2/2] simplify --- source/logrepl/internal/relationset_test.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/source/logrepl/internal/relationset_test.go b/source/logrepl/internal/relationset_test.go index 6e4e69e7..806ddf52 100644 --- a/source/logrepl/internal/relationset_test.go +++ b/source/logrepl/internal/relationset_test.go @@ -61,9 +61,7 @@ func TestRelationSetAllTypes(t *testing.T) { for { // first message needs to be a begin message msg := <-messages - if _, ok := msg.(*pglogrepl.BeginMessage); !ok { - t.Fatalf("expected begin message, got %s", msg.Type()) - } + _ = msg.(*pglogrepl.BeginMessage) // second message can be either commit (we can catch empty transactions) // or relation (that's what we are actually interested in) @@ -75,13 +73,7 @@ func TestRelationSetAllTypes(t *testing.T) { // not an empty transaction, these have to be the messages we are looking for rel = msg.(*pglogrepl.RelationMessage) // second message is a relation ins = (<-messages).(*pglogrepl.InsertMessage) // third one is the insert - - // last one needs to be commit - msg = <-messages - if _, ok := msg.(*pglogrepl.CommitMessage); !ok { - t.Fatalf("expected commit message, got %s", msg.Type()) - } - + _ = (<-messages).(*pglogrepl.CommitMessage) // fourth one is the commit break }