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

Function StartDuckSqlServer

testutil/testutil.go:53–151  ·  view source on GitHub ↗

StartDuckSqlServer starts a sql-server on a free port from the specified directory |dir|. If |peristentSystemVars| is populated, then those system variables will be set, persistently, for the database, before the sql-server is started.

(t *testing.T, dir string, persistentSystemVars map[string]string, testEnv *TestEnv)

Source from the content-addressed store, hash-verified

51
52// StartDuckSqlServer starts a sql-server on a free port from the specified directory |dir|. If
53// |peristentSystemVars| is populated, then those system variables will be set, persistently, for
54// the database, before the sql-server is started.
55func StartDuckSqlServer(t *testing.T, dir string, persistentSystemVars map[string]string, testEnv *TestEnv) error {
56 dir = filepath.Join(dir, duckSubdir)
57 err := os.MkdirAll(dir, 0777)
58 if err != nil {
59 return err
60 }
61
62 // If we already assigned a port, re-use it. This is useful when testing restarting a primary, since
63 // we want the primary to come back up on the same port, so the replica can reconnect.
64 if testEnv.DuckPort < 1 {
65 testEnv.DuckPort = FindFreePort()
66 }
67 if testEnv.DuckPgPort < 1 {
68 testEnv.DuckPgPort = FindFreePort()
69 }
70 fmt.Printf("Starting MyDuck on port: %d, PgPort: %d, with data dir %s\n", testEnv.DuckPort, testEnv.DuckPgPort, dir)
71
72 // take the CWD and move up four directories to find the go directory
73 if testEnv.OriginalWorkingDir == "" {
74 var err error
75 testEnv.OriginalWorkingDir, err = os.Getwd()
76 if err != nil {
77 panic(err)
78 }
79 }
80 goDirPath := filepath.Join(testEnv.OriginalWorkingDir, "..")
81 err = os.Chdir(goDirPath)
82 if err != nil {
83 panic(err)
84 }
85
86 args := []string{"go", "run", ".",
87 fmt.Sprintf("--port=%v", testEnv.DuckPort),
88 fmt.Sprintf("--datadir=%s", dir),
89 fmt.Sprintf("--pg-port=%v", testEnv.DuckPgPort),
90 "--default-time-zone=UTC",
91 "--loglevel=4", // 4: INFO, 5: DEBUG, 6: TRACE
92 }
93 args = append(args, testEnv.ExtraArgs...)
94
95 // If we're running in CI, use a precompiled dolt binary instead of go run
96 devBuildPath := initializeDevBuild(dir, goDirPath)
97 if devBuildPath != "" {
98 args[2] = devBuildPath
99 args = args[2:]
100 }
101 cmd := exec.Command(args[0], args[1:]...)
102
103 // Set a unique process group ID so that we can cleanly kill this process, as well as
104 // any spawned child processes later. Mac/Unix can set the "Setpgid" field directly, but
105 // on windows, this field isn't present, so we need to use reflection so that this code
106 // can still compile for windows, even though we don't run it there.
107 procAttr := &syscall.SysProcAttr{}
108 ps := reflect.ValueOf(procAttr)
109 s := ps.Elem()
110 f := s.FieldByName("Setpgid")

Callers 6

TestAutoRestartReplicaFunction · 0.92
TestCreateCatalogFunction · 0.92
TestFuncReplacementFunction · 0.92
TestSessParamFunction · 0.92

Calls 6

FindFreePortFunction · 0.85
initializeDevBuildFunction · 0.85
StopDuckSqlServerFunction · 0.85
WaitForSqlServerToStartFunction · 0.85
StartMethod · 0.65
StringMethod · 0.45

Tested by 6

TestAutoRestartReplicaFunction · 0.74
TestCreateCatalogFunction · 0.74
TestFuncReplacementFunction · 0.74
TestSessParamFunction · 0.74