Skip to content

Commit

Permalink
Modify to always track when providing; Add provider and reprovider sh…
Browse files Browse the repository at this point in the history
…arness tests

License: MIT
Signed-off-by: Michael Avila <davidmichaelavila@gmail.com>
  • Loading branch information
michaelavila committed Apr 3, 2019
1 parent c3b19d7 commit abf778e
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 152 deletions.
2 changes: 1 addition & 1 deletion core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e

subApi.routing = offlineroute.NewOfflineRouter(subApi.repo.Datastore(), subApi.recordValidator)
subApi.namesys = namesys.NewNameSystem(subApi.routing, subApi.repo.Datastore(), cs)
subApi.provider = provider.NewOfflineProvider()
//subApi.provider = provider.NewOfflineProvider()

subApi.peerstore = nil
subApi.peerHost = nil
Expand Down
4 changes: 1 addition & 3 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ func (p *provider) handleAnnouncements() {

log.Info("announce - start - ", c)
if err := p.contentRouting.Provide(p.ctx, c, true); err != nil {
log.Warningf("Unable to provide entry: %s, %s", c, err)
continue
log.Warningf("Error providing entry: %s, %s", c, err)
}
log.Info("announce - end - ", c)

if err := p.tracker.Track(c); err != nil {
log.Warningf("Unable to track entry: %s, %s", c, err)
continue
}
}
}
Expand Down
109 changes: 106 additions & 3 deletions test/sharness/lib/iptb-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ipfsi() {

check_has_connection() {
node="$1"
ipfsi "$node" swarm peers >"swarm_peers_$node" &&
ipfsi "$node" swarm peers >"swarm_peers_$node"
grep "ipfs" "swarm_peers_$node" >/dev/null
}

Expand All @@ -29,10 +29,8 @@ iptb() {
}

startup_cluster() {
num_nodes="$1"
shift
other_args="$@"
bound=$(expr "$num_nodes" - 1)

if test -n "$other_args"; then
test_expect_success "start up nodes with additional args" "
Expand All @@ -43,7 +41,11 @@ startup_cluster() {
iptb start -wait
'
fi
}

connect_cluster() {
num_nodes="$1"
bound=$(expr "$num_nodes" - 1)
test_expect_success "connect nodes to eachother" '
iptb connect [1-$bound] 0
'
Expand All @@ -62,3 +64,104 @@ iptb_wait_stop() {
go-sleep 10ms
done
}

init_cluster() {
test_expect_success "init iptb" "
iptb testbed create -type localipfs -force -count $1 -init
"

for ((i=0; i<$1; i++));
do
test_expect_success "node id $i" "
node$i=$(iptb attr get $i id)
"
done
}

start_node() {
test_expect_success "start up node $1" "
iptb start -wait $1
"
}

stop_node() {
test_expect_success "stop node $1" "
iptb stop $1
"
}

add_data_to_node() {
test_expect_success "generate test object" "
head -c 256 </dev/urandom >object$1
"

test_expect_success "add test object" "
hash$1=$(ipfsi $1 add -q "object$1")
"
}

connect_peers() {
test_expect_success "connect node $1 to node $2" "
iptb connect $1 $2
"
}

peer_id() {
test_expect_success "peer id $1" "
peer$1=$(iptb attr get $1 id)
"
}

not_find_provs() {
test_expect_success "findprovs "$2" succeeds" "
ipfsi $1 dht findprovs -n 1 "$2" > findprovs_$2
"

test_expect_success "findprovs $2 output is empty" "
test_must_be_empty findprovs_$2
"
}

find_provs() {
test_expect_success "prepare expected succeeds" "
echo $3 > expected$1
"

test_expect_success "findprovs "$2" succeeds" "
ipfsi $1 dht findprovs -n 1 "$2" > findprovs_$2
"

test_expect_success "findprovs $2 output looks good" "
test_cmp findprovs_$2 expected$1
"
}

has_no_peers() {
test_expect_success "get peers for node 0" "
ipfsi $1 swarm peers >swarm_peers_$1
"

test_expect_success "swarm_peers_$1 is empty" "
test_must_be_empty swarm_peers_$1
"
}

has_peer() {
test_expect_success "prepare expected succeeds" "
echo $2 > expected$1
"

test_expect_success "get peers for node $1" "
ipfsi $1 swarm peers >swarm_peers_$1
"

test_expect_success "swarm_peers_$1 contains $2" "
cat swarm_peers_$1 | grep $2
"
}

reprovide() {
test_expect_success "reprovide" "
ipfsi $1 bitswap reprovide
"
}
28 changes: 28 additions & 0 deletions test/sharness/t0175-provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

test_description="Test reprovider"

. lib/test-lib.sh

NUM_NODES=2

init_cluster ${NUM_NODES}

start_node 0
start_node 1

has_no_peers 0
has_no_peers 1
connect_peers 0 1
has_peer 0 $node1
has_peer 1 $node0

add_data_to_node 0

stop_node 0

find_provs 1 $hash0 $node0

stop_node 1

test_done
162 changes: 17 additions & 145 deletions test/sharness/t0175-reprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,158 +4,30 @@ test_description="Test reprovider"

. lib/test-lib.sh

NUM_NODES=6
NUM_NODES=2

init_strategy() {
test_expect_success 'init iptb' '
iptb testbed create -type localipfs -force -count $NUM_NODES -init
'
init_cluster ${NUM_NODES} # sets $node0,$node1,...,$nodeN

test_expect_success 'peer ids' '
PEERID_0=$(iptb attr get 0 id) &&
PEERID_1=$(iptb attr get 1 id)
'
start_node 0
add_data_to_node 0 # sets $hash0
stop_node 0

test_expect_success 'use pinning startegy for reprovider' '
ipfsi 0 config Reprovider.Strategy '$1'
'
start_node 1
not_find_provs 1 $hash0
start_node 0

startup_cluster ${NUM_NODES}
}
has_no_peers 0
has_no_peers 1
connect_peers 0 1
has_peer 0 $node1
has_peer 1 $node0

findprovs_empty() {
test_expect_success 'findprovs '$1' succeeds' '
ipfsi 1 dht findprovs -n 1 '$1' > findprovsOut
'
reprovide 0

test_expect_success "findprovs $1 output is empty" '
test_must_be_empty findprovsOut
'
}
stop_node 0

findprovs_expect() {
test_expect_success 'findprovs '$1' succeeds' '
ipfsi 1 dht findprovs -n 1 '$1' > findprovsOut &&
echo '$2' > expected
'
find_provs 1 $hash0 $node0

test_expect_success "findprovs $1 output looks good" '
test_cmp findprovsOut expected
'
}

reprovide() {
test_expect_success 'reprovide' '
# TODO: this hangs, though only after reprovision was done
ipfsi 0 bitswap reprovide
'
}

# Test 'all' strategy
init_strategy 'all'

test_expect_success 'add test object' '
HASH_0=$(echo "foo" | ipfsi 0 add -q --local)
'

findprovs_empty '$HASH_0'
reprovide
findprovs_expect '$HASH_0' '$PEERID_0'

test_expect_success 'Stop iptb' '
iptb stop
'

# Test 'pinned' strategy
init_strategy 'pinned'

test_expect_success 'prepare test files' '
echo foo > f1 &&
echo bar > f2
'

test_expect_success 'add test objects' '
HASH_FOO=$(ipfsi 0 add -q --offline --pin=false f1) &&
HASH_BAR=$(ipfsi 0 add -q --offline --pin=false f2) &&
HASH_BAR_DIR=$(ipfsi 0 add -q --offline -w f2)
'

findprovs_empty '$HASH_FOO'
findprovs_empty '$HASH_BAR'
findprovs_empty '$HASH_BAR_DIR'

reprovide

findprovs_empty '$HASH_FOO'
findprovs_expect '$HASH_BAR' '$PEERID_0'
findprovs_expect '$HASH_BAR_DIR' '$PEERID_0'

test_expect_success 'Stop iptb' '
iptb stop
'

# Test 'roots' strategy
init_strategy 'roots'

test_expect_success 'prepare test files' '
echo foo > f1 &&
echo bar > f2 &&
echo baz > f3
'

test_expect_success 'add test objects' '
HASH_FOO=$(ipfsi 0 add -q --offline --pin=false f1) &&
HASH_BAR=$(ipfsi 0 add -q --offline --pin=false f2) &&
HASH_BAZ=$(ipfsi 0 add -q --offline f3) &&
HASH_BAR_DIR=$(ipfsi 0 add -q --offline -w f2 | tail -1)
'

findprovs_empty '$HASH_FOO'
findprovs_empty '$HASH_BAR'
findprovs_empty '$HASH_BAR_DIR'

reprovide

findprovs_empty '$HASH_FOO'
findprovs_empty '$HASH_BAR'
findprovs_expect '$HASH_BAZ' '$PEERID_0'
findprovs_expect '$HASH_BAR_DIR' '$PEERID_0'

test_expect_success 'Stop iptb' '
iptb stop
'

# Test reprovider working with ticking disabled
test_expect_success 'init iptb' '
iptb testbed create -type localipfs -force -count $NUM_NODES -init
'

test_expect_success 'peer ids' '
PEERID_0=$(iptb attr get 0 id) &&
PEERID_1=$(iptb attr get 1 id)
'

test_expect_success 'Disable reprovider ticking' '
ipfsi 0 config Reprovider.Interval 0
'

startup_cluster ${NUM_NODES}

test_expect_success 'add test object' '
HASH_0=$(echo "foo" | ipfsi 0 add -q --offline)
'

findprovs_empty '$HASH_0'
reprovide
findprovs_expect '$HASH_0' '$PEERID_0'

test_expect_success 'resolve object $HASH_0' '
HASH_WITH_PREFIX=$(ipfsi 1 resolve $HASH_0)
'
findprovs_expect '$HASH_WITH_PREFIX' '$PEERID_0'

test_expect_success 'Stop iptb' '
iptb stop
'
stop_node 1

test_done

2 comments on commit abf778e

@GitCop
Copy link

@GitCop GitCop commented on abf778e Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

@GitCop GitCop commented on abf778e Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend can often help you quickly improve the commit message.
Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.


This message was auto-generated by https://gitcop.com

Please sign in to comment.