Skip to content

Commit 09a9e01

Browse files
dmygeroleg-jukovec
authored andcommitted
tests: add helpers for TcS
Simple helpers to make easy create tests required Taranatool centralized configuration storage.
1 parent 344cc02 commit 09a9e01

File tree

11 files changed

+579
-114
lines changed

11 files changed

+579
-114
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1212

1313
- Extend box with replication information (#427).
1414
- The Instance info has been added to ConnectionInfo for GetInfo response (#429).
15+
- Added helpers to run Tarantool config storage (#431).
1516

1617
### Changed
1718

19+
- Changed helpers API `StartTarantool` and `StopTarantool`, now it uses
20+
pointer on `TarantoolInstance`:
21+
* `StartTarantool()` returns `*TarantoolInstance`;
22+
* `StopTarantool()` and `StopTarantoolWithCleanup()` accepts
23+
`*TarantoolInstance` as arguments.
24+
- Field `Cmd` in `TarantoolInstance` struct declared as deprecated.
25+
Suggested `Wait()`, `Stop()` and `Signal()` methods as safer to use
26+
instead of direct `Cmd.Process` access (#431).
27+
1828
### Fixed
1929

30+
- Fixed flaky test detection on fail start Tarantool instance (#431).
31+
2032
## [v2.2.1] - 2024-12-17
2133

2234
The release fixes a schema lost after a reconnect.

pool/connection_pool_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var connOpts = tarantool.Opts{
9898
var defaultCountRetry = 5
9999
var defaultTimeoutRetry = 500 * time.Millisecond
100100

101-
var helpInstances []test_helpers.TarantoolInstance
101+
var helpInstances []*test_helpers.TarantoolInstance
102102

103103
func TestConnect_error_duplicate(t *testing.T) {
104104
ctx, cancel := test_helpers.GetPoolConnectContext()
@@ -404,7 +404,7 @@ func TestReconnect(t *testing.T) {
404404
defaultCountRetry, defaultTimeoutRetry)
405405
require.Nil(t, err)
406406

407-
err = test_helpers.RestartTarantool(&helpInstances[0])
407+
err = test_helpers.RestartTarantool(helpInstances[0])
408408
require.Nilf(t, err, "failed to restart tarantool")
409409

410410
args = test_helpers.CheckStatusesArgs{
@@ -453,7 +453,7 @@ func TestDisconnect_withReconnect(t *testing.T) {
453453
require.Nil(t, err)
454454

455455
// Restart the server after success.
456-
err = test_helpers.RestartTarantool(&helpInstances[serverId])
456+
err = test_helpers.RestartTarantool(helpInstances[serverId])
457457
require.Nilf(t, err, "failed to restart tarantool")
458458

459459
args = test_helpers.CheckStatusesArgs{
@@ -501,10 +501,10 @@ func TestDisconnectAll(t *testing.T) {
501501
defaultCountRetry, defaultTimeoutRetry)
502502
require.Nil(t, err)
503503

504-
err = test_helpers.RestartTarantool(&helpInstances[0])
504+
err = test_helpers.RestartTarantool(helpInstances[0])
505505
require.Nilf(t, err, "failed to restart tarantool")
506506

507-
err = test_helpers.RestartTarantool(&helpInstances[1])
507+
err = test_helpers.RestartTarantool(helpInstances[1])
508508
require.Nilf(t, err, "failed to restart tarantool")
509509

510510
args = test_helpers.CheckStatusesArgs{
@@ -1362,10 +1362,10 @@ func TestRequestOnClosed(t *testing.T) {
13621362
_, err = connPool.Ping(pool.ANY)
13631363
require.NotNilf(t, err, "err is nil after Ping")
13641364

1365-
err = test_helpers.RestartTarantool(&helpInstances[0])
1365+
err = test_helpers.RestartTarantool(helpInstances[0])
13661366
require.Nilf(t, err, "failed to restart tarantool")
13671367

1368-
err = test_helpers.RestartTarantool(&helpInstances[1])
1368+
err = test_helpers.RestartTarantool(helpInstances[1])
13691369
require.Nilf(t, err, "failed to restart tarantool")
13701370
}
13711371

queue/queue_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const (
2323
var servers = []string{"127.0.0.1:3014", "127.0.0.1:3015"}
2424
var server = "127.0.0.1:3013"
2525

26-
var instances []test_helpers.TarantoolInstance
27-
2826
var dialer = NetDialer{
2927
Address: server,
3028
User: user,
@@ -931,7 +929,7 @@ func runTestMain(m *testing.M) int {
931929
})
932930
}
933931

934-
instances, err = test_helpers.StartTarantoolInstances(poolInstsOpts)
932+
instances, err := test_helpers.StartTarantoolInstances(poolInstsOpts)
935933

936934
if err != nil {
937935
log.Printf("Failed to prepare test tarantool pool: %s", err)

shutdown_test.go

+25-58
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func testGracefulShutdown(t *testing.T, conn *Connection, inst *test_helpers.Tar
7878

7979
// SIGTERM the server.
8080
shutdownStart := time.Now()
81-
require.Nil(t, inst.Cmd.Process.Signal(syscall.SIGTERM))
81+
require.Nil(t, inst.Signal(syscall.SIGTERM))
8282

8383
// Check that we can't send new requests after shutdown starts.
8484
// Retry helps to wait a bit until server starts to shutdown
@@ -108,14 +108,11 @@ func testGracefulShutdown(t *testing.T, conn *Connection, inst *test_helpers.Tar
108108
// Wait until server go down.
109109
// Server will go down only when it process all requests from our connection
110110
// (or on timeout).
111-
_, err = inst.Cmd.Process.Wait()
111+
err = inst.Wait()
112112
require.Nil(t, err)
113113
shutdownFinish := time.Now()
114114
shutdownTime := shutdownFinish.Sub(shutdownStart)
115115

116-
// Help test helpers to properly clean up.
117-
inst.Cmd.Process = nil
118-
119116
// Check that it wasn't a timeout.
120117
require.Lessf(t,
121118
shutdownTime,
@@ -129,18 +126,16 @@ func testGracefulShutdown(t *testing.T, conn *Connection, inst *test_helpers.Tar
129126
func TestGracefulShutdown(t *testing.T) {
130127
test_helpers.SkipIfWatchersUnsupported(t)
131128

132-
var inst test_helpers.TarantoolInstance
133129
var conn *Connection
134-
var err error
135130

136-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
131+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
137132
require.Nil(t, err)
138133
defer test_helpers.StopTarantoolWithCleanup(inst)
139134

140135
conn = test_helpers.ConnectWithValidation(t, shtdnDialer, shtdnClntOpts)
141136
defer conn.Close()
142137

143-
testGracefulShutdown(t, conn, &inst)
138+
testGracefulShutdown(t, conn, inst)
144139
}
145140

146141
func TestCloseGraceful(t *testing.T) {
@@ -190,26 +185,23 @@ func TestCloseGraceful(t *testing.T) {
190185
func TestGracefulShutdownWithReconnect(t *testing.T) {
191186
test_helpers.SkipIfWatchersUnsupported(t)
192187

193-
var inst test_helpers.TarantoolInstance
194-
var err error
195-
196-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
188+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
197189
require.Nil(t, err)
198190
defer test_helpers.StopTarantoolWithCleanup(inst)
199191

200192
conn := test_helpers.ConnectWithValidation(t, shtdnDialer, shtdnClntOpts)
201193
defer conn.Close()
202194

203-
testGracefulShutdown(t, conn, &inst)
195+
testGracefulShutdown(t, conn, inst)
204196

205-
err = test_helpers.RestartTarantool(&inst)
197+
err = test_helpers.RestartTarantool(inst)
206198
require.Nilf(t, err, "Failed to restart tarantool")
207199

208200
connected := test_helpers.WaitUntilReconnected(conn, shtdnClntOpts.MaxReconnects,
209201
shtdnClntOpts.Reconnect)
210202
require.Truef(t, connected, "Reconnect success")
211203

212-
testGracefulShutdown(t, conn, &inst)
204+
testGracefulShutdown(t, conn, inst)
213205
}
214206

215207
func TestNoGracefulShutdown(t *testing.T) {
@@ -219,14 +211,12 @@ func TestNoGracefulShutdown(t *testing.T) {
219211
noShtdDialer.RequiredProtocolInfo = ProtocolInfo{}
220212
test_helpers.SkipIfWatchersSupported(t)
221213

222-
var inst test_helpers.TarantoolInstance
223214
var conn *Connection
224-
var err error
225215

226216
testSrvOpts := shtdnSrvOpts
227217
testSrvOpts.Dialer = noShtdDialer
228218

229-
inst, err = test_helpers.StartTarantool(testSrvOpts)
219+
inst, err := test_helpers.StartTarantool(testSrvOpts)
230220
require.Nil(t, err)
231221
defer test_helpers.StopTarantoolWithCleanup(inst)
232222

@@ -249,21 +239,18 @@ func TestNoGracefulShutdown(t *testing.T) {
249239

250240
// SIGTERM the server.
251241
shutdownStart := time.Now()
252-
require.Nil(t, inst.Cmd.Process.Signal(syscall.SIGTERM))
242+
require.Nil(t, inst.Signal(syscall.SIGTERM))
253243

254244
// Check that request was interrupted.
255245
_, err = fut.Get()
256246
require.NotNilf(t, err, "sleep request error")
257247

258248
// Wait until server go down.
259-
_, err = inst.Cmd.Process.Wait()
249+
err = inst.Wait()
260250
require.Nil(t, err)
261251
shutdownFinish := time.Now()
262252
shutdownTime := shutdownFinish.Sub(shutdownStart)
263253

264-
// Help test helpers to properly clean up.
265-
inst.Cmd.Process = nil
266-
267254
// Check that server finished without waiting for eval to finish.
268255
require.Lessf(t,
269256
shutdownTime,
@@ -274,11 +261,9 @@ func TestNoGracefulShutdown(t *testing.T) {
274261
func TestGracefulShutdownRespectsClose(t *testing.T) {
275262
test_helpers.SkipIfWatchersUnsupported(t)
276263

277-
var inst test_helpers.TarantoolInstance
278264
var conn *Connection
279-
var err error
280265

281-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
266+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
282267
require.Nil(t, err)
283268
defer test_helpers.StopTarantoolWithCleanup(inst)
284269

@@ -314,7 +299,7 @@ func TestGracefulShutdownRespectsClose(t *testing.T) {
314299

315300
// SIGTERM the server.
316301
shutdownStart := time.Now()
317-
require.Nil(t, inst.Cmd.Process.Signal(syscall.SIGTERM))
302+
require.Nil(t, inst.Signal(syscall.SIGTERM))
318303

319304
// Close the connection.
320305
conn.Close()
@@ -327,14 +312,11 @@ func TestGracefulShutdownRespectsClose(t *testing.T) {
327312
require.NotNilf(t, err, "sleep request error")
328313

329314
// Wait until server go down.
330-
_, err = inst.Cmd.Process.Wait()
315+
err = inst.Wait()
331316
require.Nil(t, err)
332317
shutdownFinish := time.Now()
333318
shutdownTime := shutdownFinish.Sub(shutdownStart)
334319

335-
// Help test helpers to properly clean up.
336-
inst.Cmd.Process = nil
337-
338320
// Check that server finished without waiting for eval to finish.
339321
require.Lessf(t,
340322
shutdownTime,
@@ -354,11 +336,9 @@ func TestGracefulShutdownRespectsClose(t *testing.T) {
354336
func TestGracefulShutdownNotRacesWithRequestReconnect(t *testing.T) {
355337
test_helpers.SkipIfWatchersUnsupported(t)
356338

357-
var inst test_helpers.TarantoolInstance
358339
var conn *Connection
359-
var err error
360340

361-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
341+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
362342
require.Nil(t, err)
363343
defer test_helpers.StopTarantoolWithCleanup(inst)
364344

@@ -397,16 +377,13 @@ func TestGracefulShutdownNotRacesWithRequestReconnect(t *testing.T) {
397377
fut := conn.Do(req)
398378

399379
// SIGTERM the server.
400-
require.Nil(t, inst.Cmd.Process.Signal(syscall.SIGTERM))
380+
require.Nil(t, inst.Signal(syscall.SIGTERM))
401381

402382
// Wait until server go down.
403383
// Server is expected to go down on timeout.
404-
_, err = inst.Cmd.Process.Wait()
384+
err = inst.Wait()
405385
require.Nil(t, err)
406386

407-
// Help test helpers to properly clean up.
408-
inst.Cmd.Process = nil
409-
410387
// Check that request failed by server disconnect, not a client timeout.
411388
_, err = fut.Get()
412389
require.NotNil(t, err)
@@ -425,11 +402,9 @@ func TestGracefulShutdownNotRacesWithRequestReconnect(t *testing.T) {
425402
func TestGracefulShutdownCloseConcurrent(t *testing.T) {
426403
test_helpers.SkipIfWatchersUnsupported(t)
427404

428-
var inst test_helpers.TarantoolInstance
429-
var err error
430405
var srvShtdnStart, srvShtdnFinish time.Time
431406

432-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
407+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
433408
require.Nil(t, err)
434409
defer test_helpers.StopTarantoolWithCleanup(inst)
435410

@@ -487,22 +462,19 @@ func TestGracefulShutdownCloseConcurrent(t *testing.T) {
487462
go func(inst *test_helpers.TarantoolInstance) {
488463
srvToStop.Wait()
489464
srvShtdnStart = time.Now()
490-
cerr := inst.Cmd.Process.Signal(syscall.SIGTERM)
465+
cerr := inst.Signal(syscall.SIGTERM)
491466
if cerr != nil {
492467
sret = cerr
493468
}
494469
srvStop.Done()
495-
}(&inst)
470+
}(inst)
496471

497472
srvStop.Wait()
498473
require.Nil(t, sret, "No errors on server SIGTERM")
499474

500-
_, err = inst.Cmd.Process.Wait()
475+
err = inst.Wait()
501476
require.Nil(t, err)
502477

503-
// Help test helpers to properly clean up.
504-
inst.Cmd.Process = nil
505-
506478
srvShtdnFinish = time.Now()
507479
srvShtdnTime := srvShtdnFinish.Sub(srvShtdnStart)
508480

@@ -515,11 +487,9 @@ func TestGracefulShutdownCloseConcurrent(t *testing.T) {
515487
func TestGracefulShutdownConcurrent(t *testing.T) {
516488
test_helpers.SkipIfWatchersUnsupported(t)
517489

518-
var inst test_helpers.TarantoolInstance
519-
var err error
520490
var srvShtdnStart, srvShtdnFinish time.Time
521491

522-
inst, err = test_helpers.StartTarantool(shtdnSrvOpts)
492+
inst, err := test_helpers.StartTarantool(shtdnSrvOpts)
523493
require.Nil(t, err)
524494
defer test_helpers.StopTarantoolWithCleanup(inst)
525495

@@ -577,25 +547,22 @@ func TestGracefulShutdownConcurrent(t *testing.T) {
577547
go func(inst *test_helpers.TarantoolInstance) {
578548
srvToStop.Wait()
579549
srvShtdnStart = time.Now()
580-
cerr := inst.Cmd.Process.Signal(syscall.SIGTERM)
550+
cerr := inst.Signal(syscall.SIGTERM)
581551
if cerr != nil {
582552
sret = cerr
583553
}
584554
srvStop.Done()
585-
}(&inst)
555+
}(inst)
586556

587557
srvStop.Wait()
588558
require.Nil(t, sret, "No errors on server SIGTERM")
589559

590560
caseWg.Wait()
591561
require.Nil(t, ret, "No errors on concurrent wait")
592562

593-
_, err = inst.Cmd.Process.Wait()
563+
err = inst.Wait()
594564
require.Nil(t, err)
595565

596-
// Help test helpers to properly clean up.
597-
inst.Cmd.Process = nil
598-
599566
srvShtdnFinish = time.Now()
600567
srvShtdnTime := srvShtdnFinish.Sub(srvShtdnStart)
601568

tarantool_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,7 @@ func TestConnection_NewWatcher_reconnect(t *testing.T) {
36093609
<-events
36103610

36113611
test_helpers.StopTarantool(inst)
3612-
if err := test_helpers.RestartTarantool(&inst); err != nil {
3612+
if err := test_helpers.RestartTarantool(inst); err != nil {
36133613
t.Fatalf("Unable to restart Tarantool: %s", err)
36143614
}
36153615

@@ -3902,7 +3902,7 @@ func TestConnection_named_index_after_reconnect(t *testing.T) {
39023902
t.Fatalf("An error expected.")
39033903
}
39043904

3905-
if err := test_helpers.RestartTarantool(&inst); err != nil {
3905+
if err := test_helpers.RestartTarantool(inst); err != nil {
39063906
t.Fatalf("Unable to restart Tarantool: %s", err)
39073907
}
39083908

0 commit comments

Comments
 (0)