Skip to content

Commit 9f1169c

Browse files
authored
[Test] Add more verbose (#325)
1 parent 6588c04 commit 9f1169c

File tree

6 files changed

+116
-39
lines changed

6 files changed

+116
-39
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ __test_go_test:
360360
-e TEST_BACKUP_REMOTE_CONFIG='$(TEST_BACKUP_REMOTE_CONFIG)' \
361361
-e TEST_DEBUG='$(TEST_DEBUG)' \
362362
-e TEST_ENABLE_SHUTDOWN=$(TEST_ENABLE_SHUTDOWN) \
363+
-e TEST_REQUEST_LOG=$(TEST_REQUEST_LOG) \
363364
-e GODEBUG=tls13=1 \
364365
-e CGO_ENABLED=$(CGO_ENABLED) \
365366
-w /usr/code/ \

http/response_json.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (r *httpJSONResponse) StatusCode() int {
4949
func (r *httpJSONResponse) Endpoint() string {
5050
u := *r.resp.Request.URL
5151
u.Path = ""
52+
u.RawQuery = ""
5253
return u.String()
5354
}
5455

http/response_vpack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (r *httpVPackResponse) StatusCode() int {
4747
func (r *httpVPackResponse) Endpoint() string {
4848
u := *r.resp.Request.URL
4949
u.Path = ""
50+
u.RawQuery = ""
5051
return u.String()
5152
}
5253

test/backup_test.go

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
2020
// Author Ewout Prangsma
21+
// Author Adam Janikowski
2122
//
2223

2324
package test
@@ -33,8 +34,6 @@ import (
3334
"time"
3435

3536
driver "github.com/arangodb/go-driver"
36-
37-
errors "github.com/pkg/errors"
3837
)
3938

4039
var backupAPIAvailable *bool
@@ -344,40 +343,34 @@ func TestBackupDeleteNonExisting(t *testing.T) {
344343
}
345344
}
346345

347-
func waitForServerRestart(ctx context.Context, c driver.Client, t *testing.T) {
346+
func waitForServerRestart(ctx context.Context, c driver.Client, t *testing.T) driver.Client {
347+
// Wait for server to go down
348+
newRetryFunc(func() error {
349+
c = createClientFromEnv(t, false)
350+
nCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
351+
defer cancel()
348352

349-
serverWasDown := false
353+
if _, err := c.Version(nCtx); err != nil {
354+
return interrupt{}
355+
}
350356

351-
saveDriver := driver.WithStack
352-
driver.WithStack = errors.WithStack
357+
return nil
358+
}).RetryT(t, 100*time.Millisecond, 15*time.Second)
353359

354-
for {
355-
vctx, cancel := context.WithTimeout(ctx, 50*time.Millisecond)
356-
if _, err := c.Version(vctx); err != nil {
357-
fmt.Printf("Error Response: %v\n", err)
358-
fmt.Printf("Error Response: %+v\n", err)
359-
serverWasDown = true
360-
} else {
361-
if serverWasDown {
362-
fmt.Print("Leaving successfully\n")
363-
cancel()
364-
driver.WithStack = saveDriver
365-
return
366-
}
367-
}
360+
// Wait for secret to start
361+
newRetryFunc(func() error {
362+
c = createClientFromEnv(t, false)
363+
nCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
364+
defer cancel()
368365

369-
cancel()
370-
select {
371-
case <-ctx.Done():
372-
fmt.Print("Context cancelled\n")
373-
driver.WithStack = saveDriver
374-
return
375-
case <-time.After(1 * time.Second):
376-
//fmt.Print("After 1 second\n")
377-
break
366+
if _, err := c.Version(nCtx); err == nil {
367+
return interrupt{}
378368
}
379-
}
380369

370+
return nil
371+
}).RetryT(t, 100*time.Millisecond, 15*time.Second)
372+
373+
return c
381374
}
382375

383376
func TestBackupRestore(t *testing.T) {
@@ -432,7 +425,7 @@ func TestBackupRestore(t *testing.T) {
432425
if isSingle {
433426
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
434427
defer cancel()
435-
waitForServerRestart(waitctx, c, t)
428+
c = waitForServerRestart(waitctx, c, t)
436429
}
437430

438431
if ok, err := col.DocumentExists(ctx, meta1.Key); err != nil {
@@ -683,7 +676,7 @@ func TestBackupCompleteCycle(t *testing.T) {
683676
if isSingle {
684677
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
685678
defer cancel()
686-
waitForServerRestart(waitctx, c, t)
679+
c = waitForServerRestart(waitctx, c, t)
687680
}
688681

689682
if ok, err := col.DocumentExists(ctx, meta1.Key); err != nil {
@@ -803,7 +796,7 @@ func TestBackupCreateRestoreParallel(t *testing.T) {
803796
if isSingle {
804797
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
805798
defer cancel()
806-
waitForServerRestart(waitctx, c, t)
799+
c = waitForServerRestart(waitctx, c, t)
807800
}
808801
} else {
809802
errchan <- err
@@ -901,7 +894,7 @@ func TestBackupRestoreWithViews(t *testing.T) {
901894
if isSingle {
902895
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
903896
defer cancel()
904-
waitForServerRestart(waitctx, c, t)
897+
c = waitForServerRestart(waitctx, c, t)
905898
}
906899

907900
t.Run("immediate", func(t *testing.T) {

test/client_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,8 @@ func createClientFromEnv(t testEnv, waitUntilReady bool) driver.Client {
208208
})
209209

210210
conn := createConnectionFromEnv(t)
211-
if os.Getenv("TEST_DEBUG") != "" {
212-
file, err := os.OpenFile("./test.log", os.O_CREATE|os.O_RDWR, 0666)
213-
require.NoError(t, err)
214-
l := zerolog.New(file).With().Str("Test", t.Name()).Logger()
215-
conn = wrappers.NewLoggerConnection(conn, wrappers.NewZeroLogLogger(l), true)
211+
if os.Getenv("TEST_REQUEST_LOG") != "" {
212+
conn = WrapLogger(t, conn)
216213
}
217214

218215
c, err := driver.NewClient(driver.ClientConfig{

test/wrapper_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2021 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package test
24+
25+
import (
26+
"context"
27+
"strings"
28+
"time"
29+
30+
"github.com/arangodb/go-driver"
31+
)
32+
33+
func WrapLogger(t testEnv, c driver.Connection) driver.Connection {
34+
return &logWrapper{
35+
t: t,
36+
c: c,
37+
}
38+
}
39+
40+
type logWrapper struct {
41+
t testEnv
42+
43+
c driver.Connection
44+
}
45+
46+
func (l logWrapper) NewRequest(method, path string) (driver.Request, error) {
47+
return l.c.NewRequest(method, path)
48+
}
49+
50+
func (l logWrapper) Do(ctx context.Context, req driver.Request) (driver.Response, error) {
51+
t := time.Now()
52+
53+
if resp, err := l.c.Do(ctx, req); err != nil {
54+
l.t.Logf("Request (UNKNOWN)\t%s\t%s (%s): Failed %s", strings.ToUpper(req.Method()), req.Path(), time.Now().Sub(t).String(), err.Error())
55+
return resp, err
56+
} else {
57+
l.t.Logf("Request (%s)\t%s\t%s (%s): Code %d", resp.Endpoint(), strings.ToUpper(req.Method()), req.Path(), time.Now().Sub(t).String(), resp.StatusCode())
58+
return resp, err
59+
}
60+
}
61+
62+
func (l logWrapper) Unmarshal(data driver.RawObject, result interface{}) error {
63+
return l.c.Unmarshal(data, result)
64+
}
65+
66+
func (l logWrapper) Endpoints() []string {
67+
return l.c.Endpoints()
68+
}
69+
70+
func (l logWrapper) UpdateEndpoints(endpoints []string) error {
71+
return l.c.UpdateEndpoints(endpoints)
72+
}
73+
74+
func (l logWrapper) SetAuthentication(authentication driver.Authentication) (driver.Connection, error) {
75+
if c, err := l.c.SetAuthentication(authentication); err != nil {
76+
return nil, err
77+
} else {
78+
return WrapLogger(l.t, c), nil
79+
}
80+
}
81+
82+
func (l logWrapper) Protocols() driver.ProtocolSet {
83+
return l.c.Protocols()
84+
}

0 commit comments

Comments
 (0)