Commit 0c413de8 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #3432 from keks/feat/pubsub-sharness

add sharness test for pubsub
parents a1d2d47a 993e7816
......@@ -122,30 +122,17 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
},
Marshalers: cmds.MarshalerMap{
cmds.Text: getPsMsgMarshaler(func(m *floodsub.Message) (io.Reader, error) {
if m.Message == nil {
return strings.NewReader(""), nil
}
return bytes.NewReader(m.Data), nil
}),
"ndpayload": getPsMsgMarshaler(func(m *floodsub.Message) (io.Reader, error) {
if m.Message == nil {
return strings.NewReader("\n"), nil
}
m.Data = append(m.Data, '\n')
return bytes.NewReader(m.Data), nil
}),
"lenpayload": getPsMsgMarshaler(func(m *floodsub.Message) (io.Reader, error) {
buf := make([]byte, 8)
var data []byte
if m.Message != nil {
data = m.Data
}
n := binary.PutUvarint(buf, uint64(len(data)))
return io.MultiReader(bytes.NewReader(buf[:n]), bytes.NewReader(data)), nil
n := binary.PutUvarint(buf, uint64(len(m.Data)))
return io.MultiReader(bytes.NewReader(buf[:n]), bytes.NewReader(m.Data)), nil
}),
},
Type: floodsub.Message{},
......@@ -187,6 +174,9 @@ func getPsMsgMarshaler(f func(m *floodsub.Message) (io.Reader, error)) func(cmds
if !ok {
return nil, u.ErrCast()
}
if obj.Message == nil {
return strings.NewReader(""), nil
}
return f(obj)
}
......
......@@ -19,11 +19,19 @@ check_has_connection() {
startup_cluster() {
num_nodes="$1"
shift
other_args="$@"
bound=$(expr "$num_nodes" - 1)
test_expect_success "start up nodes" '
iptb start
'
if test -n "$other_args"; then
test_expect_success "start up nodes with additional args" '
iptb start --args $other_args
'
else
test_expect_success "start up nodes" '
iptb start
'
fi
test_expect_success "connect nodes to eachother" '
iptb connect [1-$bound] 0
......
#!/bin/sh
test_description="Test dht command"
. lib/test-lib.sh
# start iptb + wait for peering
NUM_NODES=5
test_expect_success 'init iptb' '
iptb init -n $NUM_NODES --bootstrap=none --port=0
'
startup_cluster $NUM_NODES --enable-pubsub-experiment
test_expect_success 'peer ids' '
PEERID_0=$(iptb get id 0) &&
PEERID_2=$(iptb get id 2)
'
# ipfs pubsub sub
test_expect_success 'pubsub' '
echo "testOK" > expected &&
touch empty &&
mkfifo wait ||
test_fsh echo init fail
# ipfs pubsub sub is long-running so we need to start it in the background and
# wait put its output somewhere where we can access it
(
ipfsi 0 pubsub sub --enc=ndpayload testTopic | if read line; then
echo $line > actual &&
echo > wait
fi
) &
# wait until ipfs pubsub sub is ready to do work
sleep 1 &&
# publish something
ipfsi 1 pubsub pub testTopic "testOK" &> pubErr &&
# wait until `echo > wait` executed
cat wait &&
test_cmp pubErr empty &&
test_cmp expected actual
'
test_expect_success 'stop iptb' '
iptb stop
'
test_done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment