test/sharness: randomize api port workaround
we have a problem where initializing daemons with the same api port often fails-- it hangs indefinitely. The proper solution is to make ipfs pick an unused port for the api on startup, and then use that. Unfortunately, ipfs doesnt yet know how to do this-- the api port must be specified. Until ipfs learns how to do this, we must use specific port numbers, which may still fail but less frequently if we at least use different ones.
Juan Batiz-Benet committed
Mar 2, 2015 at 06:38 UTC
2a40d7679e273e7a6e52980e62f1c40181c27a06
1 file changed
+19
-1
test/sharness/lib/test-lib.sh
+19
-1
@@ -125,6 +125,24 @@ test_config_set() {
125
126
test_init_ipfs() {
127
128
+ # we have a problem where initializing daemons with the same api port
129
+ # often fails-- it hangs indefinitely. The proper solution is to make
130
+ # ipfs pick an unused port for the api on startup, and then use that.
131
+ # Unfortunately, ipfs doesnt yet know how to do this-- the api port
132
+ # must be specified. Until ipfs learns how to do this, we must use
133
+ # specific port numbers, which may still fail but less frequently
134
+ # if we at least use different ones.
135
+
136
+ # Using RANDOM like this is clearly wrong-- it samples with replacement
137
+ # and it doesnt even check the port is unused. this is a trivial stop gap
138
+ # until the proper solution is implemented.
139
+ apiport=$((RANDOM % 3000 + 5100))
140
+ ADDR_API="/ip4/127.0.0.1/tcp/$apiport"
141
+
142
+ # we set the Addresses.API config variable.
143
+ # the cli client knows to use it, so only need to set.
144
+ # todo: in the future, use env?
145
+
146
test_expect_success "ipfs init succeeds" '
147
export IPFS_PATH="$(pwd)/.go-ipfs" &&
148
ipfs init -b=1024 > /dev/null
@@ -134,6 +152,7 @@ test_init_ipfs() {
152
mkdir mountdir ipfs ipns &&
153
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
154
test_config_set Mounts.IPNS "$(pwd)/ipns" &&
155
+ test_config_set Addresses.API "$ADDR_API" &&
156
ipfs bootstrap rm --all ||
157
test_fsh cat "\"$IPFS_PATH/config\""
158
'
@@ -172,7 +191,6 @@ test_launch_ipfs_daemon() {
191
'
192
193
# we say the daemon is ready when the API server is ready.
175
- ADDR_API="/ip4/127.0.0.1/tcp/5001"
194
test_expect_success "'ipfs daemon' is ready" '
195
IPFS_PID=$! &&
196
pollEndpoint -ep=/version -host=$ADDR_API -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||