1
-#!/usr/bin/env bash
2
-#
3
-# Copyright (c) 2017 Jeromy Johnson
4
-# MIT Licensed; see the LICENSE file in this repository.
5
-#
6
-
7
-test_description="Test two ipfs nodes transferring a file"
8
-
9
-. lib/test-lib.sh
10
-
11
-check_file_fetch() {
12
- node=$1
13
- fhash=$2
14
- fname=$3
15
-
16
- test_expect_success "can fetch file" '
17
- ipfsi $node cat $fhash > fetch_out
18
- '
19
-
20
- test_expect_success "file looks good" '
21
- test_cmp $fname fetch_out
22
- '
23
-}
24
-
25
-check_dir_fetch() {
26
- node=$1
27
- ref=$2
28
-
29
- test_expect_success "node can fetch all refs for dir" '
30
- ipfsi $node refs -r $ref > /dev/null
31
- '
32
-}
33
-
34
-run_single_file_test() {
35
- test_expect_success "add a file on node1" '
36
- random 1000000 > filea &&
37
- FILEA_HASH=$(ipfsi 1 add -q filea)
38
- '
39
-
40
- check_file_fetch 0 $FILEA_HASH filea
41
-}
42
-
43
-run_random_dir_test() {
44
- test_expect_success "create a bunch of random files" '
45
- random-files -depth=3 -dirs=4 -files=5 -seed=5 foobar > /dev/null
46
- '
47
-
48
- test_expect_success "add those on node 0" '
49
- DIR_HASH=$(ipfsi 0 add -r -Q foobar)
50
- '
51
-
52
- check_dir_fetch 1 $DIR_HASH
53
-}
54
-
55
-flaky_advanced_test() {
56
- startup_cluster 2 "$@"
57
-
58
- test_expect_success "clean repo before test" '
59
- ipfsi 0 repo gc > /dev/null &&
60
- ipfsi 1 repo gc > /dev/null
61
- '
62
-
63
- run_single_file_test
64
-
65
- run_random_dir_test
66
-
67
- test_expect_success "gather bitswap stats" '
68
- ipfsi 0 bitswap stat -v > stat0 &&
69
- ipfsi 1 bitswap stat -v > stat1
70
- '
71
-
72
- test_expect_success "shut down nodes" '
73
- iptb stop && iptb_wait_stop
74
- '
75
-
76
- # NOTE: data transferred stats checks are flaky
77
- # trying to debug them by printing out the stats hides the flakiness
78
- # my theory is that the extra time cat calls take to print out the stats
79
- # allow for proper cleanup to happen
80
- go-sleep 1s
81
-}
82
-
83
-run_advanced_test() {
84
- # TODO: investigate why flaky_advanced_test is flaky
85
- # Context: https://github.com/ipfs/kubo/pull/9486
86
- # sometimes, bitswap status returns unexpected block transfers
87
- # and everyone has been re-running circleci until is passes for at least a year.
88
- # this re-runs test until it passes or a timeout hits
89
-
90
- BLOCKS_0=126
91
- BLOCKS_1=5
92
- DATA_0=228113
93
- DATA_1=1000256
94
- for i in $(test_seq 1 600); do
95
- flaky_advanced_test
96
- (grep -q "$DATA_0" stat0 && grep -q "$DATA_1" stat1) && break
97
- go-sleep 100ms
98
- done
99
-
100
- test_expect_success "node0 data transferred looks correct" '
101
- test_should_contain "blocks sent: $BLOCKS_0" stat0 &&
102
- test_should_contain "blocks received: $BLOCKS_1" stat0 &&
103
- test_should_contain "data sent: $DATA_0" stat0 &&
104
- test_should_contain "data received: $DATA_1" stat0
105
- '
106
-
107
- test_expect_success "node1 data transferred looks correct" '
108
- test_should_contain "blocks received: $BLOCKS_0" stat1 &&
109
- test_should_contain "blocks sent: $BLOCKS_1" stat1 &&
110
- test_should_contain "data received: $DATA_0" stat1 &&
111
- test_should_contain "data sent: $DATA_1" stat1
112
- '
113
-
114
-}
115
-
116
-test_expect_success "set up tcp testbed" '
117
- iptb testbed create -type localipfs -count 2 -force -init
118
-'
119
-
120
-test_expect_success "disable routing, use direct peering" '
121
- iptb run -- ipfs config Routing.Type none &&
122
- iptb run -- ipfs config --json Bootstrap "[]"
123
-'
124
-
125
-# Test TCP transport
126
-echo "Testing TCP"
127
-addrs='"[\"/ip4/127.0.0.1/tcp/0\"]"'
128
-test_expect_success "use TCP only" '
129
- iptb run -- ipfs config --json Addresses.Swarm '"${addrs}"' &&
130
- iptb run -- ipfs config --json Swarm.Transports.Network.QUIC false &&
131
- iptb run -- ipfs config --json Swarm.Transports.Network.Relay false &&
132
- iptb run -- ipfs config --json Swarm.Transports.Network.WebTransport false &&
133
- iptb run -- ipfs config --json Swarm.Transports.Network.Websocket false
134
-'
135
-run_advanced_test
136
-
137
-# test multiplex muxer
138
-echo "Running TCP tests with mplex"
139
-test_expect_success "disable yamux" '
140
- iptb run -- ipfs config --json Swarm.Transports.Multiplexers.Yamux false
141
-'
142
-run_advanced_test
143
-
144
-test_expect_success "re-enable yamux" '
145
- iptb run -- ipfs config --json Swarm.Transports.Multiplexers.Yamux null
146
-'
147
-# test Noise
148
-echo "Running TCP tests with NOISE"
149
-test_expect_success "use noise only" '
150
- iptb run -- ipfs config --json Swarm.Transports.Security.TLS false
151
-'
152
-run_advanced_test
153
-
154
-test_expect_success "re-enable TLS" '
155
- iptb run -- ipfs config --json Swarm.Transports.Security.TLS null
156
-'
157
-
158
-# test QUIC
159
-echo "Running advanced tests over QUIC"
160
-addrs='"[\"/ip4/127.0.0.1/udp/0/quic-v1\"]"'
161
-test_expect_success "use QUIC only" '
162
- iptb run -- ipfs config --json Addresses.Swarm '"${addrs}"' &&
163
- iptb run -- ipfs config --json Swarm.Transports.Network.QUIC true &&
164
- iptb run -- ipfs config --json Swarm.Transports.Network.TCP false
165
-'
166
-run_advanced_test
167
-
168
-# test WebTransport
169
-echo "Running advanced tests over WebTransport"
170
-addrs='"[\"/ip4/127.0.0.1/udp/0/quic-v1/webtransport\"]"'
171
-test_expect_success "use WebTransport only" '
172
- iptb run -- ipfs config --json Addresses.Swarm '"${addrs}"' &&
173
- iptb run -- ipfs config --json Swarm.Transports.Network.QUIC true &&
174
- iptb run -- ipfs config --json Swarm.Transports.Network.WebTransport true
175
-'
176
-run_advanced_test
177
-
178
-test_done