Skip to content

Commit d960571

Browse files
to #246 fix: bugs in replication_test.go.
1 parent a6aa161 commit d960571

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pgserver/logrepl/replication_test.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package logrepl_test
1717
import (
1818
"context"
1919
"fmt"
20+
"github.com/apecloud/myduckserver/adapter"
21+
"github.com/jackc/pglogrepl"
2022
"log"
2123
"os"
2224
"os/exec"
@@ -660,6 +662,7 @@ func RunReplicationScripts(t *testing.T, scripts []ReplicationTest) {
660662
}
661663

662664
const slotName = "myduck_slot"
665+
const subscriptionName = "my_sub_test"
663666

664667
// RunReplicationScript runs the given ReplicationTest.
665668
func RunReplicationScript(t *testing.T, dsn string, script ReplicationTest) {
@@ -686,8 +689,18 @@ func RunReplicationScript(t *testing.T, dsn string, script ReplicationTest) {
686689
})
687690
}
688691

689-
func newReplicator(t *testing.T, primaryDns string) *logrepl.LogicalReplicator {
690-
r, err := logrepl.NewLogicalReplicator("mySubTest", primaryDns)
692+
func newReplicator(sqlCtx *sql.Context, t *testing.T, primaryDns string) *logrepl.LogicalReplicator {
693+
err := logrepl.CreateSubscription(sqlCtx, subscriptionName, primaryDns, slotName, pglogrepl.LSN(0).String(), true)
694+
require.NoError(t, err)
695+
696+
tx := adapter.TryGetTxn(sqlCtx)
697+
if tx != nil {
698+
err := tx.Commit()
699+
require.NoError(t, err)
700+
adapter.CloseTxn(sqlCtx)
701+
}
702+
703+
r, err := logrepl.NewLogicalReplicator(subscriptionName, primaryDns)
691704
require.NoError(t, err)
692705
return r
693706
}
@@ -701,7 +714,7 @@ func runReplicationScript(
701714
replicaConn *pgx.Conn,
702715
primaryDns string,
703716
) {
704-
r := newReplicator(t, primaryDns)
717+
r := newReplicator(server.NewInternalCtx(), t, primaryDns)
705718
defer r.Stop()
706719

707720
if script.Skip {

0 commit comments

Comments
 (0)