feat: re-enable docker sharness tests (#8808)
The Docker sharness tests were disabled years ago when go-ipfs moved from Travis to CircleCI. This makes the tweaks necessary to re-enable them. The Docker image has since moved to be based on BusyBox which doesn't have the requisite wget version for the existing tests to work, so this adds some functionality to the pollEndpoint program to support polling HTTP endpoints as well.
Gus Eggert committed
Mar 30, 2022 at 11:07 UTC
46c3689b7506c8166f8f96f42d597ad6a816257f
6 files changed
+89
-31
.circleci/main.yml
+1
-1
@@ -154,7 +154,7 @@ jobs:
154
working_directory: ~/ipfs/go-ipfs
155
environment:
156
<<: *default_environment
157
- TEST_NO_DOCKER: 1
157
+ TEST_NO_DOCKER: 0
158
TEST_NO_FUSE: 1
159
TEST_VERBOSE: 1
160
steps:
.dockerignore
+2
@@ -5,6 +5,8 @@ Dockerfile.fast
5
!.git/refs/
6
!.git/packed-refs
7
test/sharness/lib/sharness/
8
+test/sharness/trash*
9
+rb-pinning-service-api/
10
11
# The Docker client might not be running on Linux
12
# so delete any compiled binaries
test/dependencies/pollEndpoint/main.go
+68
-4
@@ -2,7 +2,11 @@
2
package main
3
4
import (
5
+ "context"
6
"flag"
7
+ "io"
8
+ "net"
9
+ "net/http"
10
"os"
11
"time"
12
@@ -15,6 +19,8 @@ var (
19
host = flag.String("host", "/ip4/127.0.0.1/tcp/5001", "the multiaddr host to dial on")
20
tries = flag.Int("tries", 10, "how many tries to make before failing")
21
timeout = flag.Duration("tout", time.Second, "how long to wait between attempts")
22
+ httpURL = flag.String("http-url", "", "HTTP URL to fetch")
23
+ httpOut = flag.Bool("http-out", false, "Print the HTTP response body to stdout")
24
verbose = flag.Bool("v", false, "verbose logging")
25
)
26
@@ -37,18 +43,76 @@ func main() {
43
start := time.Now()
44
log.Debugf("starting at %s, tries: %d, timeout: %s, addr: %s", start, *tries, *timeout, addr)
45
40
- for *tries > 0 {
46
+ connTries := *tries
47
+ for connTries > 0 {
48
c, err := manet.Dial(addr)
49
if err == nil {
50
log.Debugf("ok - endpoint reachable with %d tries remaining, took %s", *tries, time.Since(start))
51
c.Close()
45
- os.Exit(0)
52
+ break
53
}
54
log.Debug("connect failed: ", err)
55
time.Sleep(*timeout)
49
- *tries--
56
+ connTries--
57
}
58
52
- log.Error("failed.")
59
+ if err != nil {
60
+ goto Fail
61
+ }
62
+
63
+ if *httpURL != "" {
64
+ dialer := &connDialer{addr: addr}
65
+ httpClient := http.Client{Transport: &http.Transport{
66
+ DialContext: dialer.DialContext,
67
+ }}
68
+ reqTries := *tries
69
+ for reqTries > 0 {
70
+ try := (*tries - reqTries) + 1
71
+ log.Debugf("trying HTTP req %d: '%s'", try, *httpURL)
72
+ if tryHTTPGet(&httpClient, *httpURL) {
73
+ log.Debugf("HTTP req %d to '%s' succeeded", try, *httpURL)
74
+ goto Success
75
+ }
76
+ log.Debugf("HTTP req %d to '%s' failed", try, *httpURL)
77
+ time.Sleep(*timeout)
78
+ reqTries--
79
+ }
80
+ goto Fail
81
+ }
82
+
83
+Success:
84
+ os.Exit(0)
85
+
86
+Fail:
87
+ log.Error("failed")
88
os.Exit(1)
89
}
90
+
91
+func tryHTTPGet(client *http.Client, url string) bool {
92
+ resp, err := client.Get(*httpURL)
93
+ if resp != nil && resp.Body != nil {
94
+ defer resp.Body.Close()
95
+ }
96
+ if err != nil {
97
+ return false
98
+ }
99
+ if resp.StatusCode != http.StatusOK {
100
+ return false
101
+ }
102
+ if *httpOut {
103
+ _, err := io.Copy(os.Stdout, resp.Body)
104
+ if err != nil {
105
+ panic(err)
106
+ }
107
+ }
108
+
109
+ return true
110
+}
111
+
112
+type connDialer struct {
113
+ addr ma.Multiaddr
114
+}
115
+
116
+func (d connDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
117
+ return (&manet.Dialer{}).DialContext(ctx, d.addr)
118
+}
test/ipfs-test-lib.sh
+1
-6
@@ -62,12 +62,7 @@ docker_run() {
62
63
# This takes a docker ID and a command as arguments
64
docker_exec() {
65
- if test "$CIRCLE" = 1
66
- then
67
- sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' $1)" -- /bin/bash -c "$2"
68
- else
69
- docker exec -t "$1" /bin/bash -c "$2"
70
- fi
65
+ docker exec -t "$1" /bin/sh -c "$2"
66
}
67
68
# This takes a docker ID as argument
test/sharness/t0300-docker-image.sh
+10
-13
@@ -29,30 +29,28 @@ TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
29
APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
30
31
test_expect_success "docker image build succeeds" '
32
- docker_build "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" >actual ||
32
+ docker_build "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" >build-actual ||
33
test_fsh echo "TEST_TESTS_DIR: $TEST_TESTS_DIR" ||
34
test_fsh echo "APP_ROOT_DIR : $APP_ROOT_DIR" ||
35
- test_fsh cat actual
35
+ test_fsh cat build-actual
36
'
37
38
test_expect_success "docker image build output looks good" '
39
- SUCCESS_LINE=$(egrep "^Successfully built" actual) &&
39
+ SUCCESS_LINE=$(egrep "^Successfully built" build-actual) &&
40
IMAGE_ID=$(expr "$SUCCESS_LINE" : "^Successfully built \(.*\)") ||
41
- test_fsh cat actual
41
+ test_fsh cat build-actual
42
'
43
44
test_expect_success "docker image runs" '
45
- DOC_ID=$(docker_run "$IMAGE_ID")
45
+ DOC_ID=$(docker run -d -p 127.0.0.1:5001:5001 -p 127.0.0.1:8080:8080 "$IMAGE_ID")
46
'
47
48
-test_expect_success "docker image gateway is up" '
49
- docker_exec "$DOC_ID" "wget --retry-connrefused --waitretry=1 --timeout=30 -t 30 \
50
- -q -O - http://localhost:8080/version >/dev/null"
48
+test_expect_success "docker container gateway is up" '
49
+ pollEndpoint -host=/ip4/127.0.0.1/tcp/8080 -http-url http://localhost:8080/api/v0/version -v -tries 30 -tout 1s
50
'
51
53
-test_expect_success "docker image API is up" '
54
- docker_exec "$DOC_ID" "wget --retry-connrefused --waitretry=1 --timeout=30 -t 30 \
55
- -q -O - http://localhost:5001/api/v0/version >/dev/null"
52
+test_expect_success "docker container API is up" '
53
+ pollEndpoint -host=/ip4/127.0.0.1/tcp/5001 -http-url http://localhost:5001/version -v -tries 30 -tout 1s
54
'
55
56
test_expect_success "simple ipfs add/cat can be run in docker container" '
@@ -63,8 +61,7 @@ test_expect_success "simple ipfs add/cat can be run in docker container" '
61
'
62
63
read testcode <<EOF
66
- docker exec -i "$DOC_ID" wget --retry-connrefused --waitretry=1 --timeout=30 -t 30 \
67
- -q -O - http://localhost:8080/version | grep Commit | cut -d" " -f2 >actual ; \
64
+ pollEndpoint -host=/ip4/127.0.0.1/tcp/5001 -http-url http://localhost:5001/version -http-out | grep Commit | cut -d" " -f2 >actual ; \
65
test -s actual ; \
66
docker exec -i "$DOC_ID" ipfs version --enc json \
67
| sed 's/^.*"Commit":"\\\([^"]*\\\)".*$/\\\1/g' >expected ; \
test/sharness/t0301-docker-migrate.sh
+7
-7
@@ -32,6 +32,10 @@ test_expect_success "docker image build succeeds" '
32
33
test_init_ipfs
34
35
+test_expect_success "configure migration sources" '
36
+ ipfs config --json Migration.DownloadSources "[\"http://127.0.0.1:17233\"]"
37
+'
38
+
39
test_expect_success "make repo be version 4" '
40
echo 4 > "$IPFS_PATH/version"
41
'
@@ -43,17 +47,13 @@ test_expect_success "setup http response" '
47
echo "v1.1.1" >> vers_resp
48
'
49
46
-pretend_server() {
47
- socat tcp-listen:17233,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat vers_resp'!!STDERR &
48
-}
49
-
50
test_expect_success "startup fake dists server" '
51
- pretend_server > dist_serv_out &
51
+ ( socat tcp-listen:17233,fork,bind=127.0.0.1,reuseaddr "SYSTEM:cat vers_resp"!!STDERR 2> dist_serv_out ) &
52
echo $! > netcat_pid
53
'
54
55
test_expect_success "docker image runs" '
56
- DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs --net=host -e IPFS_DIST_PATH="http://localhost:17233" "$IMAGE_ID" --migrate)
56
+ DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs --net=host "$IMAGE_ID")
57
'
58
59
test_expect_success "docker container tries to pull migrations from netcat" '
@@ -74,7 +74,7 @@ test_expect_success "kill the net cat" '
74
'
75
76
test_expect_success "correct version was requested" '
77
- grep "/fs-repo-migrations/v1.1.1/fs-repo-migrations_v1.1.1_linux-amd64.tar.gz" dist_serv_out > /dev/null
77
+ grep "/fs-repo-6-to-7/v1.1.1/fs-repo-6-to-7_v1.1.1_linux-amd64.tar.gz" dist_serv_out > /dev/null
78
'
79
80
test_done