tests: wait for up to 5 seconds for start-up, not just 3s
[iwhd.git] / t / replication
blob835fa6879a861045e6967cf02d8a969468bb478b
1 #!/bin/sh
2 # Test replication functionality.
4 # TEST-FILE USAGE
5 # dflt_test default policy (negative)
6 # pos_test always-replicate policy (positive)
7 # sel_pos selective positive, delete
8 # sel_neg selective negative
9 # attr_chg attribute change (positive)
11 . "${srcdir=.}/init.sh"; path_prepend_ ..
13 mkdir mongod fs_upstream fs_downstream || framework_failure_ mkdir failed
15 m_port=$(expr $mongo_base_port + 1)
17 mongod --port $m_port --pidfilepath mongod/pid --dbpath mongod > mongod.log 2>&1 &
18 mongo_pid=$!
19 cleanup_() { kill -9 $mongo_pid; }
21 # Wait for up to 12 seconds for mongod to begin listening.
22 wait_for .1 120 'mongo localhost:$m_port < /dev/null' \
23 || framework_failure_ mongod failed to start
25 cat > iwhd_u.cfg << EOF
27 { "name":"upstream", "type":"fs", "path":"fs_upstream" },
28 { "name":"downstream", "type":"http", "host":"localhost", "port": 9093,
29 "color": "blue" }
31 EOF
33 port=9092
34 iwhd -v -p $port -c iwhd_u.cfg -d localhost:$m_port &
35 iwhd_pid=$!
36 wait_for .1 50 "curl http://localhost:$port" \
37 || framework_failure_ "iwhd upstream"
38 cleanup_() { kill -9 $mongo_pid; kill $iwhd_pid; }
40 cat > iwhd_d.cfg << EOF
42 {"name": "downstream", "type": "fs", "path": "fs_downstream" }
44 EOF
46 d_port=9093
47 iwhd -v -p $d_port -c iwhd_d.cfg -d localhost:$m_port -m localhost:$port &
48 iwhd_d_pid=$!
49 wait_for .1 50 "curl http://localhost:$d_port" \
50 || framework_failure_ "iwhd downstream"
51 cleanup_() { kill -9 $mongo_pid; kill $iwhd_pid $iwhd_d_pid; }
53 api=http://localhost:$port
54 wait_for_repl() {
55 local n_req=$(curl -d op=rep_status $api) || return 1
56 case $n_req in
57 '0 requests') return 0 ;;
58 *) return 1 ;;
59 esac
61 bkt=$api/rbucket
63 # Create a bucket to work in.
64 curl -X PUT $bkt || fail=1
65 # Make sure it exists at both ends (i.e. create was replicated).
66 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
67 test -d fs_upstream/rbucket || fail=1
68 test -d fs_downstream/rbucket || fail=1
70 # Add a file, make sure it's *not* replicated (default policy).
71 echo foo | curl -T - $bkt/dflt_test || fail=1
72 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
73 test -f fs_upstream/rbucket/dflt_test || fail=1
74 test -f fs_downstream/rbucket/dflt_test && fail=1
76 # Set the replication policy to always replicate.
77 echo -n 1 | curl -T - $bkt/_default/_policy || fail=1
79 # Add a file, make sure it *is* replicated.
80 echo foo | curl -T - $bkt/pos_test || fail=1
81 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
82 test -f fs_upstream/rbucket/pos_test || fail=1
83 test -f fs_downstream/rbucket/pos_test || fail=1
85 # Make sure we can do selective replication based on object/site attributes.
86 echo -n '$color==#color' | curl -T - $bkt/_default/_policy || fail=1
88 # Positive test.
89 # NB this file is also used by the delete test below
90 echo -n blue | curl -T - $bkt/sel_pos/color || fail=1
91 echo -n foo | curl -T - $bkt/sel_pos || fail=1
92 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
93 test -f fs_downstream/rbucket/sel_pos || fail=1
95 # Negative test.
96 echo -n red | curl -T - $bkt/sel_neg/color || fail=1
97 echo -n foo | curl -T - $bkt/sel_neg || fail=1
98 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
99 test -f fs_downstream/rbucket/sel_neg && fail=1
101 # Test replication of deletes.
102 curl -X DELETE $bkt/sel_pos || fail=1
103 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
104 test -f fs_upstream/rbucket/sel_pos && fail=1
105 test -f fs_downstream/rbucket/sel_pos && fail=1
107 # Test re-replication when we change an attribute.
108 echo hello | curl -T - $bkt/attr_chg
109 echo -n 'red' | curl -T - $bkt/attr_chg/color
110 echo -n '$color=="blue"' | curl -T - $bkt/attr_chg/_policy
111 test -f fs_downstream/rbucket/attr_chg && fail=1
112 echo -n 'blue' | curl -T - $bkt/attr_chg/color
113 wait_for .1 50 "wait_for_repl $api" || fail_ "replication seems stuck"
114 test -f fs_downstream/rbucket/attr_chg || fail=1
116 # TBD: add op=check result checks
118 Exit $fail