Skip to content

Commit

Permalink
Fix sharness
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
  • Loading branch information
hsanjuan committed Nov 28, 2017
1 parent 4a7c609 commit 74fa816
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
17 changes: 7 additions & 10 deletions sharness/lib/test-lib.sh
Expand Up @@ -6,8 +6,8 @@
SHARNESS_LIB="lib/sharness/sharness.sh"

# Daemons output will be redirected to...
#IPFS_OUTPUT="/dev/null" # change for debugging
IPFS_OUTPUT="/dev/stderr" # change for debugging
IPFS_OUTPUT="/dev/null" # change for debugging
#IPFS_OUTPUT="/dev/stderr" # change for debugging

. "$SHARNESS_LIB" || {
echo >&2 "Cannot source: $SHARNESS_LIB"
Expand Down Expand Up @@ -71,10 +71,7 @@ test_cluster_init() {
if [ -n "$custom_config_files" ]; then
cp -f ${custom_config_files}/* "test-config"
fi
ipfs-cluster-service --config "test-config" >"$IPFS_OUTPUT" 2>&1 &
export CLUSTER_D_PID=$!
sleep 5
test_set_prereq CLUSTER
cluster_start
}

test_cluster_config() {
Expand All @@ -100,13 +97,14 @@ test_confirm_v1State() {

cluster_kill(){
kill -1 "$CLUSTER_D_PID"
sleep 20
sleep 4
}

cluster_start(){
ipfs-cluster-service --config "test-config" >"$IPFS_OUTPUT" 2>&1 &
export CLUSTER_D_PID=$!
sleep 40
sleep 5
test_set_prereq CLUSTER
}


Expand All @@ -118,7 +116,6 @@ test_clean_ipfs(){
}

test_clean_cluster(){
kill -1 "$CLUSTER_D_PID"
cluster_kill
rm -rf 'test-config'
sleep 2
}
16 changes: 12 additions & 4 deletions sharness/t0050-service-state-upgrade-from-current.sh
Expand Up @@ -9,12 +9,20 @@ cleanup test_clean_ipfs
test_cluster_init
cleanup test_clean_cluster

test_expect_success IPFS,CLUSTER "cluster-service state preserved by migration" '
test_expect_success IPFS,CLUSTER "cluster-service state upgrade works" '
cid=`docker exec ipfs sh -c "echo testing | ipfs add -q"` &&
ipfs-cluster-ctl pin add "$cid" && sleep 30 &&
ipfs-cluster-ctl pin add "$cid" &&
sleep 2 &&
cluster_kill &&
ipfs-cluster-service --config "test-config" state upgrade >/dev/stderr &&
cluster_start &&
ipfs-cluster-service -d --config "test-config" state upgrade &>state-upgrade-cmd.txt
'

# previous test kills the cluster, we need to re-start
# if done inside the test, we lose debugging output
cluster_start

test_expect_success IPFS,CLUSTER "state is preserved after migration" '
cid=`docker exec ipfs sh -c "echo testing | ipfs add -q"` &&
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
'
Expand Down
14 changes: 7 additions & 7 deletions sharness/t0051-service-state-upgrade-from-old.sh
Expand Up @@ -18,14 +18,14 @@ cleanup test_clean_cluster
test_expect_success IPFS,CLUSTER,V1STATE,JQ "cluster-service loads v1 state correctly" '
cid=`docker exec ipfs sh -c "echo test | ipfs add -q"` &&
cid2=`docker exec ipfs sh -c "echo testing | ipfs add -q"` &&
ipfs-cluster-ctl pin add "$cid2" && sleep 30 &&
ipfs-cluster-ctl pin add "$cid2" &&
cluster_kill &&
SNAP_DIR="test-config/ipfs-cluster-data/snapshots/" &&
SNAP_DIR+="$( ls test-config/ipfs-cluster-data/snapshots/ | head -n 1)" &&
cp v1State $SNAP_DIR/state.bin &&
cat $SNAP_DIR/meta.json | jq --arg CRC "$V1_CRC" '"'"'.CRC = $CRC'"'"' > tmp.json&&
cp tmp.json $SNAP_DIR/meta.json &&
ipfs-cluster-service --config "test-config" state upgrade >/dev/stderr &&
sleep 15 &&
SNAP_DIR=`find test-config/ipfs-cluster-data/snapshots/ -maxdepth 1 -mindepth 1 | head -n 1` &&
cp v1State "$SNAP_DIR/state.bin" &&
cat "$SNAP_DIR/meta.json" | jq --arg CRC "$V1_CRC" '"'"'.CRC = $CRC'"'"' > tmp.json &&
cp tmp.json "$SNAP_DIR/meta.json" &&
ipfs-cluster-service --debug --config "test-config" state upgrade &&
cluster_start &&
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
Expand Down

0 comments on commit 74fa816

Please sign in to comment.