|
1 | 1 | package multi
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "log" |
| 5 | + "os" |
4 | 6 | "testing"
|
5 | 7 | "time"
|
6 | 8 |
|
7 | 9 | "github.com/tarantool/go-tarantool"
|
| 10 | + "github.com/tarantool/go-tarantool/test_helpers" |
8 | 11 | )
|
9 | 12 |
|
10 | 13 | var server1 = "127.0.0.1:3013"
|
@@ -204,3 +207,54 @@ func TestRefresh(t *testing.T) {
|
204 | 207 | t.Error("Expect to get data after reconnect")
|
205 | 208 | }
|
206 | 209 | }
|
| 210 | + |
| 211 | +// runTestMain is a body of TestMain function |
| 212 | +// (see https://pkg.go.dev/testing#hdr-Main). |
| 213 | +// Using defer + os.Exit is not works so TestMain body |
| 214 | +// is a separate function, see |
| 215 | +// https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls |
| 216 | +func runTestMain(m *testing.M) int { |
| 217 | + initScript := "config.lua" |
| 218 | + waitStart := 100 * time.Millisecond |
| 219 | + var connectRetry uint = 3 |
| 220 | + retryTimeout := 200 * time.Millisecond |
| 221 | + |
| 222 | + inst1, err := test_helpers.StartTarantool(test_helpers.StartOpts{ |
| 223 | + InitScript: initScript, |
| 224 | + Listen: server1, |
| 225 | + WorkDir: "work_dir1", |
| 226 | + User: connOpts.User, |
| 227 | + Pass: connOpts.Pass, |
| 228 | + WaitStart: waitStart, |
| 229 | + ConnectRetry: connectRetry, |
| 230 | + RetryTimeout: retryTimeout, |
| 231 | + }) |
| 232 | + defer test_helpers.StopTarantoolWithCleanup(inst1) |
| 233 | + |
| 234 | + if err != nil { |
| 235 | + log.Fatalf("Failed to prepare test tarantool: %s", err) |
| 236 | + } |
| 237 | + |
| 238 | + inst2, err := test_helpers.StartTarantool(test_helpers.StartOpts{ |
| 239 | + InitScript: initScript, |
| 240 | + Listen: server2, |
| 241 | + WorkDir: "work_dir2", |
| 242 | + User: connOpts.User, |
| 243 | + Pass: connOpts.Pass, |
| 244 | + WaitStart: waitStart, |
| 245 | + ConnectRetry: connectRetry, |
| 246 | + RetryTimeout: retryTimeout, |
| 247 | + }) |
| 248 | + defer test_helpers.StopTarantoolWithCleanup(inst2) |
| 249 | + |
| 250 | + if err != nil { |
| 251 | + log.Fatalf("Failed to prepare test tarantool: %s", err) |
| 252 | + } |
| 253 | + |
| 254 | + return m.Run() |
| 255 | +} |
| 256 | + |
| 257 | +func TestMain(m *testing.M) { |
| 258 | + code := runTestMain(m) |
| 259 | + os.Exit(code) |
| 260 | +} |
0 commit comments