runReplicationScript runs the script given on the postgres connection provided. This does not handle assertions that use ExpectedRaw.
( ctx context.Context, t *testing.T, script ReplicationTest, replicaConn *pgx.Conn, primaryDns string, )
| 583 | // runReplicationScript runs the script given on the postgres connection provided. This does not handle assertions that |
| 584 | // use ExpectedRaw. |
| 585 | func runReplicationScript( |
| 586 | ctx context.Context, |
| 587 | t *testing.T, |
| 588 | script ReplicationTest, |
| 589 | replicaConn *pgx.Conn, |
| 590 | primaryDns string, |
| 591 | ) { |
| 592 | walFile := fmt.Sprintf("%s/%s", t.TempDir(), "wal") |
| 593 | r := newReplicator(t, walFile, replicaConn, primaryDns) |
| 594 | defer r.Stop() |
| 595 | |
| 596 | if script.Skip { |
| 597 | t.Skip("Skip has been set in the script") |
| 598 | } |
| 599 | |
| 600 | connections := map[string]*pgx.Conn{ |
| 601 | "replica": replicaConn, |
| 602 | } |
| 603 | |
| 604 | defer func() { |
| 605 | for _, conn := range connections { |
| 606 | if conn != nil { |
| 607 | conn.Close(ctx) |
| 608 | } |
| 609 | } |
| 610 | }() |
| 611 | |
| 612 | // Run the setup |
| 613 | for _, query := range script.SetUpScript { |
| 614 | // handle logic for special pseudo-queries |
| 615 | if handlePseudoQuery(t, query, r) { |
| 616 | continue |
| 617 | } |
| 618 | |
| 619 | conn := connectionForQuery(t, query, connections, primaryDns) |
| 620 | log.Println("Running setup query:", query) |
| 621 | _, err := conn.Exec(ctx, query) |
| 622 | require.NoError(t, err) |
| 623 | } |
| 624 | |
| 625 | // Run the assertions |
| 626 | for _, assertion := range script.Assertions { |
| 627 | t.Run(assertion.Query, func(t *testing.T) { |
| 628 | if assertion.Skip { |
| 629 | t.Skip("Skip has been set in the assertion") |
| 630 | } |
| 631 | |
| 632 | // handle logic for special pseudo-queries |
| 633 | if handlePseudoQuery(t, assertion.Query, r) { |
| 634 | return |
| 635 | } |
| 636 | |
| 637 | target, _ := clientSpecFromQueryComment(assertion.Query) |
| 638 | enableRetries := target == "replica" |
| 639 | conn := connectionForQuery(t, assertion.Query, connections, primaryDns) |
| 640 | |
| 641 | numRetries := 3 |
| 642 | for retries := 0; retries < numRetries; retries++ { |
no test coverage detected