MCPcopy Create free account
hub / github.com/apecloud/myduckserver / runReplicationScript

Function runReplicationScript

pgserver/logrepl/replication_test.go:738–836  ·  view source on GitHub ↗

runReplicationScript runs the script given on the postgres connection provided

(
	ctx context.Context,
	t *testing.T,
	script ReplicationTest,
	server *pgserver.Server,
	replicaConn *pgx.Conn,
	primaryDns string,
)

Source from the content-addressed store, hash-verified

736
737// runReplicationScript runs the script given on the postgres connection provided
738func runReplicationScript(
739 ctx context.Context,
740 t *testing.T,
741 script ReplicationTest,
742 server *pgserver.Server,
743 replicaConn *pgx.Conn,
744 primaryDns string,
745) {
746 r := newReplicator(server.NewInternalCtx(), t, primaryDns)
747 defer r.Stop()
748
749 if script.Skip {
750 t.Skip("Skip has been set in the script")
751 }
752
753 connections := map[string]*pgx.Conn{
754 "replica": replicaConn,
755 }
756
757 defer func() {
758 for _, conn := range connections {
759 if conn != nil {
760 conn.Close(ctx)
761 }
762 }
763 }()
764
765 // Run the setup
766 for _, query := range script.SetUpScript {
767 // handle logic for special pseudo-queries
768 if handlePseudoQuery(t, server, query, r) {
769 continue
770 }
771
772 conn := connectionForQuery(t, query, connections, primaryDns)
773
774 target, _ := clientSpecFromQueryComment(query)
775 if target == "replica" && configuration.IsReplicationWithoutIndex() {
776 // Remove the primary key index from the replica table
777 query = strings.Replace(query, " primary key,", ",", 1)
778 }
779
780 log.Println("Running setup query:", query)
781 _, err := conn.Exec(ctx, query)
782 require.NoError(t, err)
783 }
784
785 // Run the assertions
786 for _, assertion := range script.Assertions {
787 t.Run(assertion.Query, func(t *testing.T) {
788 if assertion.Skip {
789 t.Skip("Skip has been set in the assertion")
790 }
791
792 // handle logic for special pseudo-queries
793 if handlePseudoQuery(t, server, assertion.Query, r) {
794 return
795 }

Callers 1

RunReplicationScriptFunction · 0.85

Calls 10

ReadRowsFunction · 0.92
NormalizeExpectedRowFunction · 0.92
newReplicatorFunction · 0.85
handlePseudoQueryFunction · 0.85
connectionForQueryFunction · 0.85
CloseMethod · 0.65
StopMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected