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

Function RunReplicationScripts

pgserver/logrepl/replication_test.go:648–691  ·  view source on GitHub ↗

RunScripts runs the given collection of scripts.

(t *testing.T, scripts []ReplicationTest)

Source from the content-addressed store, hash-verified

646
647// RunScripts runs the given collection of scripts.
648func RunReplicationScripts(t *testing.T, scripts []ReplicationTest) {
649 // First, we'll run through the scripts to check for the Focus variable. If it's true, then append it to the new slice.
650 focusScripts := make([]ReplicationTest, 0, len(scripts))
651 for _, script := range scripts {
652 if script.Focus {
653 // If this is running in GitHub Actions, then we'll panic, because someone forgot to disable it before committing
654 if _, ok := os.LookupEnv("GITHUB_ACTION"); ok {
655 panic(fmt.Sprintf("The script `%s` has Focus set to `true`. GitHub Actions requires that "+
656 "all tests are run, which Focus circumvents, leading to this error. Please disable Focus on "+
657 "all tests.", script.Name))
658 }
659 focusScripts = append(focusScripts, script)
660 }
661 }
662 // If we have scripts with Focus set, then we replace the normal script slice with the new slice.
663 if len(focusScripts) > 0 {
664 scripts = focusScripts
665 }
666
667 // start the docker container
668 containerName, dsn, _, err := StartPostgresServer()
669 require.NoError(t, err)
670 defer func() {
671 err := exec.Command("docker", "kill", containerName).Run()
672 require.NoError(t, err)
673 }()
674
675 primaryDns := dsn + "?sslmode=disable"
676
677 // We drop and recreate the replication slot once at the beginning of the test suite. Postgres seems to do a little
678 // work in the background with a publication, so we need to wait a little bit before running any test scripts.
679 require.NoError(t, logrepl.DropPublication(primaryDns, slotName))
680 require.NoError(t, logrepl.CreatePublicationIfNotExists(primaryDns, slotName))
681 time.Sleep(500 * time.Millisecond)
682
683 // for i, script := range scripts {
684 // if i == 10 {
685 // RunReplicationScript(t, dsn, script)
686 // }
687 // }
688 for _, script := range scripts {
689 RunReplicationScript(t, dsn, script)
690 }
691}
692
693const slotName = "myduck_slot"
694const subscriptionName = "my_sub_test"

Callers 1

TestReplicationFunction · 0.85

Calls 5

DropPublicationFunction · 0.92
StartPostgresServerFunction · 0.85
RunReplicationScriptFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected