Merge pull request #862 from ipfs/fix/raft-state-sharness
Sharness: run state import/export with both crdt and raft
This commit is contained in:
commit
7136d143fa
|
@ -80,7 +80,7 @@ test_cluster_init() {
|
|||
if [ -n "$custom_config_files" ]; then
|
||||
cp -f ${custom_config_files}/* "test-config"
|
||||
fi
|
||||
cluster_start
|
||||
cluster_start $2
|
||||
}
|
||||
|
||||
test_cluster_config() {
|
||||
|
@ -114,15 +114,19 @@ test_confirm_importState() {
|
|||
}
|
||||
|
||||
cluster_kill(){
|
||||
kill -1 "$CLUSTER_D_PID" &>/dev/null
|
||||
pkill -1 -f ipfs-cluster-service
|
||||
while pgrep ipfs-cluster-service >/dev/null; do
|
||||
sleep 0.2
|
||||
done
|
||||
}
|
||||
|
||||
cluster_start(){
|
||||
ipfs-cluster-service --config "test-config" daemon --consensus crdt >"$IPFS_OUTPUT" 2>&1 &
|
||||
export CLUSTER_D_PID=$!
|
||||
consensus="$1"
|
||||
if [ -z "$consensus" ]; then
|
||||
consensus="crdt"
|
||||
fi
|
||||
|
||||
ipfs-cluster-service --config "test-config" daemon --consensus "$consensus" >"$IPFS_OUTPUT" 2>&1 &
|
||||
while ! curl -s 'localhost:9095/api/v0/version' >/dev/null; do
|
||||
sleep 0.2
|
||||
done
|
||||
|
|
|
@ -7,8 +7,8 @@ test_description="Test service state export"
|
|||
test_ipfs_init
|
||||
test_cluster_init
|
||||
|
||||
test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to expected file" '
|
||||
cid=`docker exec ipfs sh -c "echo test_52 | ipfs add -q"` &&
|
||||
test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to expected file (crdt)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_52-1 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" &&
|
||||
sleep 5 &&
|
||||
cluster_kill && sleep 5 &&
|
||||
|
@ -17,6 +17,19 @@ test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to exp
|
|||
jq -r ".cid | .[\"/\"]" export.json | grep -q "$cid"
|
||||
'
|
||||
|
||||
cluster_kill
|
||||
cluster_start raft
|
||||
|
||||
test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to expected file (raft)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_52-2 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" &&
|
||||
sleep 5 &&
|
||||
cluster_kill && sleep 5 &&
|
||||
ipfs-cluster-service --debug --config "test-config" state export --consensus raft -f export.json &&
|
||||
[ -f export.json ] &&
|
||||
jq -r ".cid | .[\"/\"]" export.json | grep -q "$cid"
|
||||
'
|
||||
|
||||
test_clean_ipfs
|
||||
test_clean_cluster
|
||||
|
||||
|
|
|
@ -11,17 +11,39 @@ test_confirm_importState
|
|||
# Kill cluster daemon but keep data folder
|
||||
cluster_kill
|
||||
|
||||
test_expect_success IPFS,CLUSTER "state import fails on incorrect format" '
|
||||
|
||||
# WARNING: Updating the added content needs updating the importState file.
|
||||
|
||||
test_expect_success IPFS,CLUSTER "state import fails on incorrect format (crdt)" '
|
||||
sleep 5 &&
|
||||
echo "not exactly json" > badImportFile &&
|
||||
test_expect_code 1 ipfs-cluster-service --config "test-config" state import --consensus crdt -f badImportFile
|
||||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER,IMPORTSTATE "state import succeeds on correct format" '
|
||||
test_expect_success IPFS,CLUSTER,IMPORTSTATE "state import succeeds on correct format (crdt)" '
|
||||
sleep 5
|
||||
cid=`docker exec ipfs sh -c "echo test_53 | ipfs add -q"` &&
|
||||
ipfs-cluster-service --debug --config "test-config" state import --consensus crdt -f importState &&
|
||||
cluster_start &&
|
||||
ipfs-cluster-service --config "test-config" state import --consensus crdt -f importState &&
|
||||
cluster_start crdt &&
|
||||
sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
|
||||
'
|
||||
|
||||
# Kill cluster daemon but keep data folder
|
||||
cluster_kill
|
||||
|
||||
test_expect_success IPFS,CLUSTER "state import fails on incorrect format (raft)" '
|
||||
sleep 5 &&
|
||||
echo "not exactly json" > badImportFile &&
|
||||
test_expect_code 1 ipfs-cluster-service --config "test-config" state import --consensus raft -f badImportFile
|
||||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER,IMPORTSTATE "state import succeeds on correct format (raft)" '
|
||||
sleep 5
|
||||
cid=`docker exec ipfs sh -c "echo test_53 | ipfs add -q"` &&
|
||||
ipfs-cluster-service --config "test-config" state import --consensus raft -f importState &&
|
||||
cluster_start raft &&
|
||||
sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
|
||||
|
|
|
@ -7,32 +7,63 @@ test_description="Test service state import"
|
|||
test_ipfs_init
|
||||
test_cluster_init
|
||||
|
||||
test_expect_success IPFS,CLUSTER "state cleanup refreshes state on restart" '
|
||||
test_expect_success IPFS,CLUSTER "state cleanup refreshes state on restart (crdt)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" && sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
|
||||
cluster_kill && sleep 5 &&
|
||||
ipfs-cluster-service --debug --config "test-config" state cleanup --consensus crdt -f &&
|
||||
ipfs-cluster-service --config "test-config" state cleanup --consensus crdt -f &&
|
||||
cluster_start && sleep 5 &&
|
||||
[ 0 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ]
|
||||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER "export + cleanup + import == noop" '
|
||||
test_expect_success IPFS,CLUSTER "export + cleanup + import == noop (crdt)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" && sleep 5 &&
|
||||
ipfs-cluster-ctl pin add "$cid" && sleep 5 &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
|
||||
cluster_kill && sleep 5 &&
|
||||
ipfs-cluster-service --debug --config "test-config" state export --consensus crdt -f import.json &&
|
||||
ipfs-cluster-service --debug --config "test-config" state cleanup --consensus crdt -f &&
|
||||
ipfs-cluster-service --debug --config "test-config" state import --consensus crdt -f import.json &&
|
||||
ipfs-cluster-service --config "test-config" state export --consensus crdt -f import.json &&
|
||||
ipfs-cluster-service --config "test-config" state cleanup --consensus crdt -f &&
|
||||
ipfs-cluster-service --config "test-config" state import --consensus crdt -f import.json &&
|
||||
cluster_start && sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ]
|
||||
'
|
||||
|
||||
cluster_kill
|
||||
sleep 5
|
||||
cluster_start "raft"
|
||||
|
||||
test_expect_success IPFS,CLUSTER "state cleanup refreshes state on restart (raft)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" && sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
|
||||
cluster_kill && sleep 5 &&
|
||||
ipfs-cluster-service --config "test-config" state cleanup --consensus raft -f &&
|
||||
cluster_start raft && sleep 5 &&
|
||||
[ 0 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ]
|
||||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER "export + cleanup + import == noop (raft)" '
|
||||
cid=`docker exec ipfs sh -c "echo test_54 | ipfs add -q"` &&
|
||||
ipfs-cluster-ctl pin add "$cid" && sleep 5 &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
|
||||
cluster_kill && sleep 5 &&
|
||||
ipfs-cluster-service --config "test-config" state export --consensus raft -f import.json &&
|
||||
ipfs-cluster-service --config "test-config" state cleanup --consensus raft -f &&
|
||||
ipfs-cluster-service --config "test-config" state import --consensus raft -f import.json &&
|
||||
cluster_start raft && sleep 5 &&
|
||||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
|
||||
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ]
|
||||
'
|
||||
|
||||
|
||||
test_clean_ipfs
|
||||
test_clean_cluster
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user