MCPcopy Create free account
hub / github.com/dolthub/doltgresql / runReplicationScript

Function runReplicationScript

testing/go/replication_test.go:585–676  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

583// runReplicationScript runs the script given on the postgres connection provided. This does not handle assertions that
584// use ExpectedRaw.
585func 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++ {

Callers 1

RunReplicationScriptFunction · 0.85

Calls 15

newReplicatorFunction · 0.85
handlePseudoQueryFunction · 0.85
connectionForQueryFunction · 0.85
NormalizeExpectedRowFunction · 0.85
TempDirMethod · 0.80
ExecMethod · 0.80
RunMethod · 0.80
ReadRowsFunction · 0.70
CloseMethod · 0.65
StopMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected