Skip to content

Commit 1bd61d1

Browse files
DifferentialOrangeoleg-jukovec
authored andcommitted
test: separate SSL server and client check
Current SSL tests are as follows. We start a Tarantool server with default helpers. "ok" tests are successful if everything had started, "fail" tests are successful if ping check had failed (aka we failed to connect). This is a dangerous approach, since "server had failed to start" here is indistinguishable from "client cannot connect". Moreover, because of it each tnt_fail test runs for 5 seconds (10 retry attempts * 500 ms retry wait), which is frustrating. After this patch, there is a separate check for a server start and for a client success or fail.
1 parent 8ede061 commit 1bd61d1

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

ssl_test.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func createClientServerSslOk(t testing.TB, serverOpts,
9494
return l, c, msgs, errs
9595
}
9696

97-
func serverTnt(serverOpts, clientOpts SslOpts, auth Auth) (test_helpers.TarantoolInstance, error) {
97+
func serverTnt(serverOpts SslOpts, auth Auth) (test_helpers.TarantoolInstance, error) {
9898
listen := tntHost + "?transport=ssl&"
9999

100100
key := serverOpts.KeyFile
@@ -126,7 +126,7 @@ func serverTnt(serverOpts, clientOpts SslOpts, auth Auth) (test_helpers.Tarantoo
126126
SslCertsDir: "testdata",
127127
ClientServer: tntHost,
128128
ClientTransport: "ssl",
129-
ClientSsl: clientOpts,
129+
ClientSsl: serverOpts,
130130
User: "test",
131131
Pass: "test",
132132
WaitStart: 100 * time.Millisecond,
@@ -139,6 +139,23 @@ func serverTntStop(inst test_helpers.TarantoolInstance) {
139139
test_helpers.StopTarantoolWithCleanup(inst)
140140
}
141141

142+
func checkTntConn(clientOpts SslOpts) error {
143+
conn, err := Connect(tntHost, Opts{
144+
Auth: AutoAuth,
145+
Timeout: 500 * time.Millisecond,
146+
User: "test",
147+
Pass: "test",
148+
SkipSchema: true,
149+
Transport: "ssl",
150+
Ssl: clientOpts,
151+
})
152+
if err != nil {
153+
return err
154+
}
155+
conn.Close()
156+
return nil
157+
}
158+
142159
func assertConnectionSslFail(t testing.TB, serverOpts, clientOpts SslOpts) {
143160
t.Helper()
144161

@@ -171,9 +188,13 @@ func assertConnectionSslOk(t testing.TB, serverOpts, clientOpts SslOpts) {
171188
func assertConnectionTntFail(t testing.TB, serverOpts, clientOpts SslOpts) {
172189
t.Helper()
173190

174-
inst, err := serverTnt(serverOpts, clientOpts, AutoAuth)
175-
serverTntStop(inst)
191+
inst, err := serverTnt(serverOpts, AutoAuth)
192+
defer serverTntStop(inst)
193+
if err != nil {
194+
t.Fatalf("An unexpected server error %q", err.Error())
195+
}
176196

197+
err = checkTntConn(clientOpts)
177198
if err == nil {
178199
t.Errorf("An unexpected connection to the server")
179200
}
@@ -182,11 +203,15 @@ func assertConnectionTntFail(t testing.TB, serverOpts, clientOpts SslOpts) {
182203
func assertConnectionTntOk(t testing.TB, serverOpts, clientOpts SslOpts) {
183204
t.Helper()
184205

185-
inst, err := serverTnt(serverOpts, clientOpts, AutoAuth)
186-
serverTntStop(inst)
206+
inst, err := serverTnt(serverOpts, AutoAuth)
207+
defer serverTntStop(inst)
208+
if err != nil {
209+
t.Fatalf("An unexpected server error %q", err.Error())
210+
}
187211

212+
err = checkTntConn(clientOpts)
188213
if err != nil {
189-
t.Errorf("An unexpected server error %q", err.Error())
214+
t.Errorf("An unexpected connection error %q", err.Error())
190215
}
191216
}
192217

@@ -470,10 +495,11 @@ func TestOpts_PapSha256Auth(t *testing.T) {
470495
KeyFile: "testdata/localhost.key",
471496
CertFile: "testdata/localhost.crt",
472497
}
473-
inst, err := serverTnt(sslOpts, sslOpts, PapSha256Auth)
498+
499+
inst, err := serverTnt(sslOpts, PapSha256Auth)
474500
defer serverTntStop(inst)
475501
if err != nil {
476-
t.Errorf("An unexpected server error: %s", err)
502+
t.Fatalf("An unexpected server error %q", err.Error())
477503
}
478504

479505
clientOpts := opts

0 commit comments

Comments
 (0)