Skip to content

Commit 18855f1

Browse files
test: generate tmp work dirs
Generate tmp work directories for each new Tarantool instance. It prevents possible directory clash issues. Part of #215
1 parent 9648c4f commit 18855f1

File tree

10 files changed

+20
-45
lines changed

10 files changed

+20
-45
lines changed

connection_pool/connection_pool_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,18 +2379,14 @@ func runTestMain(m *testing.M) int {
23792379
waitStart := 100 * time.Millisecond
23802380
connectRetry := 3
23812381
retryTimeout := 500 * time.Millisecond
2382-
workDirs := []string{
2383-
"work_dir1", "work_dir2",
2384-
"work_dir3", "work_dir4",
2385-
"work_dir5"}
23862382

23872383
// Tarantool supports streams and interactive transactions since version 2.10.0
23882384
isStreamUnsupported, err := test_helpers.IsTarantoolVersionLess(2, 10, 0)
23892385
if err != nil {
23902386
log.Fatalf("Could not check the Tarantool version")
23912387
}
23922388

2393-
instances, err = test_helpers.StartTarantoolInstances(servers, workDirs, test_helpers.StartOpts{
2389+
instances, err = test_helpers.StartTarantoolInstances(servers, test_helpers.StartOpts{
23942390
InitScript: initScript,
23952391
User: connOpts.User,
23962392
Pass: connOpts.Pass,

datetime/datetime_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ func runTestMain(m *testing.M) int {
11411141
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
11421142
InitScript: "config.lua",
11431143
Listen: server,
1144-
WorkDir: "work_dir",
11451144
User: opts.User,
11461145
Pass: opts.Pass,
11471146
WaitStart: 100 * time.Millisecond,

decimal/decimal_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ func runTestMain(m *testing.M) int {
613613
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
614614
InitScript: "config.lua",
615615
Listen: server,
616-
WorkDir: "work_dir",
617616
User: opts.User,
618617
Pass: opts.Pass,
619618
WaitStart: 100 * time.Millisecond,

multi/multi_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ func runTestMain(m *testing.M) int {
592592
inst1, err := test_helpers.StartTarantool(test_helpers.StartOpts{
593593
InitScript: initScript,
594594
Listen: server1,
595-
WorkDir: "work_dir1",
596595
User: connOpts.User,
597596
Pass: connOpts.Pass,
598597
WaitStart: waitStart,
@@ -609,7 +608,6 @@ func runTestMain(m *testing.M) int {
609608
inst2, err := test_helpers.StartTarantool(test_helpers.StartOpts{
610609
InitScript: initScript,
611610
Listen: server2,
612-
WorkDir: "work_dir2",
613611
User: connOpts.User,
614612
Pass: connOpts.Pass,
615613
WaitStart: waitStart,

queue/queue_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,6 @@ func runTestMain(m *testing.M) int {
899899
inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
900900
InitScript: "testdata/config.lua",
901901
Listen: server,
902-
WorkDir: "work_dir",
903902
User: opts.User,
904903
Pass: opts.Pass,
905904
WaitStart: 100 * time.Millisecond,
@@ -913,15 +912,14 @@ func runTestMain(m *testing.M) int {
913912

914913
defer test_helpers.StopTarantoolWithCleanup(inst)
915914

916-
workDirs := []string{"work_dir1", "work_dir2"}
917915
poolOpts := test_helpers.StartOpts{
918916
InitScript: "testdata/pool.lua",
919917
User: opts.User,
920918
Pass: opts.Pass,
921919
WaitStart: 3 * time.Second, // replication_timeout * 3
922920
ConnectRetry: -1,
923921
}
924-
instances, err = test_helpers.StartTarantoolInstances(serversPool, workDirs, poolOpts)
922+
instances, err = test_helpers.StartTarantoolInstances(serversPool, poolOpts)
925923

926924
if err != nil {
927925
log.Fatalf("Failed to prepare test tarantool pool: %s", err)

ssl_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func serverTnt(serverOpts, clientOpts SslOpts) (test_helpers.TarantoolInstance,
126126
ClientServer: tntHost,
127127
ClientTransport: "ssl",
128128
ClientSsl: clientOpts,
129-
WorkDir: "work_dir_ssl",
130129
User: "test",
131130
Pass: "test",
132131
WaitStart: 100 * time.Millisecond,

tarantool_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
var startOpts test_helpers.StartOpts = test_helpers.StartOpts{
2424
InitScript: "config.lua",
2525
Listen: server,
26-
WorkDir: "work_dir",
2726
User: opts.User,
2827
Pass: opts.Pass,
2928
WaitStart: 100 * time.Millisecond,
@@ -3317,7 +3316,6 @@ func TestConnection_NewWatcher_reconnect(t *testing.T) {
33173316
inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
33183317
InitScript: "config.lua",
33193318
Listen: server,
3320-
WorkDir: "work_dir",
33213319
User: opts.User,
33223320
Pass: opts.Pass,
33233321
WaitStart: 100 * time.Millisecond,

test_helpers/main.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ type StartOpts struct {
4747
// a Tarantool instance.
4848
ClientSsl tarantool.SslOpts
4949

50-
// WorkDir is box.cfg work_dir parameter for tarantool.
51-
// Specify folder to store tarantool data files.
52-
// Folder must be unique for each tarantool process used simultaneously.
53-
// https://www.tarantool.io/en/doc/latest/reference/configuration/#confval-work_dir
54-
WorkDir string
55-
5650
// SslCertsDir is a path to a directory with SSL certificates. It will be
5751
// copied to the working directory.
5852
SslCertsDir string
@@ -84,6 +78,10 @@ type TarantoolInstance struct {
8478
// Cmd is a Tarantool command. Used to kill Tarantool process.
8579
Cmd *exec.Cmd
8680

81+
// WorkDir is box.cfg work_dir parameter for Tarantool.
82+
// https://www.tarantool.io/en/doc/latest/reference/configuration/#confval-work_dir
83+
WorkDir string
84+
8785
// Options for restarting a tarantool instance.
8886
Opts StartOpts
8987
}
@@ -189,30 +187,26 @@ func RestartTarantool(inst *TarantoolInstance) error {
189187
func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
190188
// Prepare tarantool command.
191189
var inst TarantoolInstance
190+
191+
// Create work_dir for a new instance.
192+
dir, err := os.MkdirTemp("", "work_dir")
193+
if err != nil {
194+
return inst, err
195+
}
196+
inst.WorkDir = dir
197+
192198
inst.Cmd = exec.Command("tarantool", startOpts.InitScript)
193199

194200
inst.Cmd.Env = append(
195201
os.Environ(),
196-
fmt.Sprintf("TEST_TNT_WORK_DIR=%s", startOpts.WorkDir),
202+
fmt.Sprintf("TEST_TNT_WORK_DIR=%s", inst.WorkDir),
197203
fmt.Sprintf("TEST_TNT_LISTEN=%s", startOpts.Listen),
198204
fmt.Sprintf("TEST_TNT_MEMTX_USE_MVCC_ENGINE=%t", startOpts.MemtxUseMvccEngine),
199205
)
200206

201-
// Clean up existing work_dir.
202-
err := os.RemoveAll(startOpts.WorkDir)
203-
if err != nil {
204-
return inst, err
205-
}
206-
207-
// Create work_dir.
208-
err = os.Mkdir(startOpts.WorkDir, 0755)
209-
if err != nil {
210-
return inst, err
211-
}
212-
213207
// Copy SSL certificates.
214208
if startOpts.SslCertsDir != "" {
215-
err = copySslCerts(startOpts.WorkDir, startOpts.SslCertsDir)
209+
err = copySslCerts(inst.WorkDir, startOpts.SslCertsDir)
216210
if err != nil {
217211
return inst, err
218212
}
@@ -289,8 +283,8 @@ func StopTarantool(inst TarantoolInstance) {
289283
func StopTarantoolWithCleanup(inst TarantoolInstance) {
290284
StopTarantool(inst)
291285

292-
if inst.Opts.WorkDir != "" {
293-
if err := os.RemoveAll(inst.Opts.WorkDir); err != nil {
286+
if inst.WorkDir != "" {
287+
if err := os.RemoveAll(inst.WorkDir); err != nil {
294288
log.Fatalf("Failed to clean work directory, got %s", err)
295289
}
296290
}

test_helpers/pool_helper.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,11 @@ func SetClusterRO(servers []string, connOpts tarantool.Opts, roles []bool) error
218218
return nil
219219
}
220220

221-
func StartTarantoolInstances(servers []string, workDirs []string, opts StartOpts) ([]TarantoolInstance, error) {
222-
if len(servers) != len(workDirs) {
223-
return nil, fmt.Errorf("number of servers should be equal to number of workDirs")
224-
}
225-
221+
func StartTarantoolInstances(servers []string, opts StartOpts) ([]TarantoolInstance, error) {
226222
instances := make([]TarantoolInstance, 0, len(servers))
227223

228-
for i, server := range servers {
224+
for _, server := range servers {
229225
opts.Listen = server
230-
opts.WorkDir = workDirs[i]
231226

232227
instance, err := StartTarantool(opts)
233228
if err != nil {

uuid/uuid_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func runTestMain(m *testing.M) int {
155155
inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
156156
InitScript: "config.lua",
157157
Listen: server,
158-
WorkDir: "work_dir",
159158
User: opts.User,
160159
Pass: opts.Pass,
161160
WaitStart: 100 * time.Millisecond,

0 commit comments

Comments
 (0)