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:
Hector Sanjuan 2019-08-05 13:28:47 +02:00 committed by GitHub
commit 7136d143fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 17 deletions

View File

@ -80,7 +80,7 @@ test_cluster_init() {
if [ -n "$custom_config_files" ]; then if [ -n "$custom_config_files" ]; then
cp -f ${custom_config_files}/* "test-config" cp -f ${custom_config_files}/* "test-config"
fi fi
cluster_start cluster_start $2
} }
test_cluster_config() { test_cluster_config() {
@ -114,15 +114,19 @@ test_confirm_importState() {
} }
cluster_kill(){ cluster_kill(){
kill -1 "$CLUSTER_D_PID" &>/dev/null pkill -1 -f ipfs-cluster-service
while pgrep ipfs-cluster-service >/dev/null; do while pgrep ipfs-cluster-service >/dev/null; do
sleep 0.2 sleep 0.2
done done
} }
cluster_start(){ cluster_start(){
ipfs-cluster-service --config "test-config" daemon --consensus crdt >"$IPFS_OUTPUT" 2>&1 & consensus="$1"
export CLUSTER_D_PID=$! 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 while ! curl -s 'localhost:9095/api/v0/version' >/dev/null; do
sleep 0.2 sleep 0.2
done done

View File

@ -7,8 +7,8 @@ test_description="Test service state export"
test_ipfs_init test_ipfs_init
test_cluster_init test_cluster_init
test_expect_success IPFS,CLUSTER,JQ "state export saves the correct state to expected file" ' 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 | ipfs add -q"` && cid=`docker exec ipfs sh -c "echo test_52-1 | ipfs add -q"` &&
ipfs-cluster-ctl pin add "$cid" && ipfs-cluster-ctl pin add "$cid" &&
sleep 5 && sleep 5 &&
cluster_kill && 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" 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_ipfs
test_clean_cluster test_clean_cluster

View File

@ -11,17 +11,39 @@ test_confirm_importState
# Kill cluster daemon but keep data folder # Kill cluster daemon but keep data folder
cluster_kill 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 && sleep 5 &&
echo "not exactly json" > badImportFile && echo "not exactly json" > badImportFile &&
test_expect_code 1 ipfs-cluster-service --config "test-config" state import --consensus crdt -f 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 sleep 5
cid=`docker exec ipfs sh -c "echo test_53 | ipfs add -q"` && 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 && ipfs-cluster-service --config "test-config" state import --consensus crdt -f importState &&
cluster_start && 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 && sleep 5 &&
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" && ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"

View File

@ -7,32 +7,63 @@ test_description="Test service state import"
test_ipfs_init test_ipfs_init
test_cluster_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"` && 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 &&
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" && ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" && ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] && [ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
cluster_kill && sleep 5 && 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 && cluster_start && sleep 5 &&
[ 0 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] [ 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"` && 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")" ] && [ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] &&
cluster_kill && sleep 5 && cluster_kill && sleep 5 &&
ipfs-cluster-service --debug --config "test-config" state export --consensus crdt -f import.json && ipfs-cluster-service --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 --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 import --consensus crdt -f import.json &&
cluster_start && sleep 5 && cluster_start && sleep 5 &&
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" && ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" && ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" &&
[ 1 -eq "$(ipfs-cluster-ctl --enc=json status | jq ". | length")" ] [ 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_ipfs
test_clean_cluster test_clean_cluster