t0240-republisher.sh 1.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/sh
#
# Copyright (c) 2014 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test ipfs repo operations"

. lib/test-lib.sh

export DEBUG=true

setup_iptb() {
Christian Couder's avatar
Christian Couder committed
14 15 16
	num_nodes="$1"
	bound=$(expr "$num_nodes" - 1)

17
	test_expect_success "iptb init" '
Jeromy's avatar
Jeromy committed
18
		iptb init -n $num_nodes --bootstrap none --port 0
19 20
	'

Christian Couder's avatar
Christian Couder committed
21 22 23 24 25 26 27
	for i in $(test_seq 0 "$bound")
	do
		test_expect_success "set configs up for node $i" '
			ipfsi "$i" config Ipns.RepublishPeriod 20s &&
			ipfsi "$i" config --json Ipns.ResolveCacheSize 0
		'
	done
28

Christian Couder's avatar
Christian Couder committed
29
	startup_cluster "$num_nodes"
30 31 32 33 34 35 36 37 38
}

teardown_iptb() {
	test_expect_success "shut down nodes" '
		iptb kill
	'
}

verify_can_resolve() {
Christian Couder's avatar
Christian Couder committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
	num_nodes="$1"
	bound=$(expr "$num_nodes" - 1)
	name="$2"
	expected="$3"
	msg="$4"

	for node in $(test_seq 0 "$bound")
	do
		test_expect_success "$msg: node $node can resolve entry" '
			ipfsi "$node" name resolve "$name" > resolve
		'

		test_expect_success "$msg: output for node $node looks right" '
			printf "/ipfs/$expected\n" > expected &&
			test_cmp expected resolve
		'
	done
56 57 58
}

verify_cannot_resolve() {
Christian Couder's avatar
Christian Couder committed
59 60 61 62 63 64 65 66 67 68 69 70 71
	num_nodes="$1"
	bound=$(expr "$num_nodes" - 1)
	name="$2"
	msg="$3"

	for node in $(test_seq 0 "$bound")
	do
		test_expect_success "$msg: resolution fails on node $node" '
			# TODO: this should work without the timeout option
			# but it currently hangs for some reason every so often
			test_expect_code 1 ipfsi "$node" name resolve --timeout=300ms "$name"
		'
	done
72 73
}

Christian Couder's avatar
Christian Couder committed
74 75 76
num_test_nodes=4

setup_iptb "$num_test_nodes"
77 78 79 80 81 82

test_expect_success "publish succeeds" '
	HASH=$(echo "foobar" | ipfsi 1 add -q) &&
	ipfsi 1 name publish -t 5s $HASH
'

Christian Couder's avatar
Christian Couder committed
83 84
test_expect_success "get id succeeds" '
	id=$(ipfsi 1 id -f "<id>")
85 86
'

Christian Couder's avatar
Christian Couder committed
87
verify_can_resolve "$num_test_nodes" "$id" "$HASH" "just after publishing"
88

Christian Couder's avatar
Christian Couder committed
89 90 91 92 93 94 95
go-sleep 5s

verify_cannot_resolve "$num_test_nodes" "$id" "after five seconds, records are invalid"

go-sleep 15s

verify_can_resolve "$num_test_nodes" "$id" "$HASH" "republisher fires after twenty seconds"
96 97 98 99

teardown_iptb

test_done