t0240-republisher.sh 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/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() {
	test_expect_success "iptb init" '
		iptb init -n4 --bootstrap none --port 0
	'

	test_expect_success "set configs up" '
19
		for i in $(test_seq 0 3)
20 21
		do
			ipfsi $i config Ipns.RepublishPeriod 20s
22
			ipfsi $i config --json Ipns.ResolveCacheSize 0
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
		done
	'

	test_expect_success "start up nodes" '
		iptb start
	'

	test_expect_success "connect nodes" '
		iptb connect 0 1 &&
		iptb connect 0 2 &&
		iptb connect 0 3
	'

	test_expect_success "nodes have connections" '
		ipfsi 0 swarm peers | grep ipfs &&
		ipfsi 1 swarm peers | grep ipfs &&
		ipfsi 2 swarm peers | grep ipfs &&
		ipfsi 3 swarm peers | grep ipfs
	'
}

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

verify_can_resolve() {
	node=$1
	name=$2
	expected=$3

	test_expect_success "node can resolve entry" '
		ipfsi $node name resolve $name > resolve
	'

	test_expect_success "output looks right" '
60
		printf "/ipfs/$expected\n" > expected &&
61
		test_cmp expected resolve
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	'
}

verify_cannot_resolve() {
	node=$1
	name=$2

	echo "verifying resolution fails on node $node"
	test_expect_success "node cannot resolve entry" '
		# 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
	'
}

setup_iptb

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

test_expect_success "other nodes can resolve" '
	id=$(ipfsi 1 id -f "<id>") &&
	verify_can_resolve 0 $id $HASH &&
	verify_can_resolve 1 $id $HASH &&
	verify_can_resolve 2 $id $HASH &&
	verify_can_resolve 3 $id $HASH
'

test_expect_success "after five seconds, records are invalid" '
	go-sleep 5s &&
	verify_cannot_resolve 0 $id &&
	verify_cannot_resolve 1 $id &&
	verify_cannot_resolve 2 $id &&
	verify_cannot_resolve 3 $id
'

test_expect_success "republisher fires after twenty seconds" '
	go-sleep 15s &&
	verify_can_resolve 0 $id $HASH &&
	verify_can_resolve 1 $id $HASH &&
	verify_can_resolve 2 $id $HASH &&
	verify_can_resolve 3 $id $HASH
'

teardown_iptb

test_done