Skip to content

Commit

Permalink
Merge branch 'compatibility-issue'
Browse files Browse the repository at this point in the history
  • Loading branch information
dedok committed Dec 7, 2015
2 parents 297db53 + f802d3e commit 22fe3ee
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ tp_dump:
-o misc/tp_dump \
-lyajl_s

test: utils build
test-dev: utils build
$(CUR_PATH)/test/transcode.sh
$(CUR_PATH)/test/nginx-tnt.sh

test: utils build
$(CUR_PATH)/test/transcode.sh
$(CUR_PATH)/test/client.py

clean:
$(MAKE) -C $(NGX_PATH) clean 2>1 || echo "pass"
rm -f misc/tp_{send,dump} misc/json2tp
Expand Down
6 changes: 5 additions & 1 deletion test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def batch_cases():
}

])

assert(rc == 200), 'expected 200'
assert(len(res) == 2), 'expected 2 elements, got %i' % len(res)
assert(get_result_i(res, 0)[1] == '101234567891234567')
Expand Down Expand Up @@ -130,12 +131,15 @@ def batch_cases():
])
assert(rc == 200), 'expected 200'
for rr in res:
if rr['id'] == 1 or rr['id'] == 3:
if rr['id'] == 3:
assert('error' in rr or 'message' in rr), \
'expected %s returns error/message, got %s' % (rr['id'], rr)
elif rr['id'] == 2:
rr_ = get_result(rr)
assert(rr_[1] == '101234567891234567')
elif rr['id'] == 1:
rr_ = get_result(rr)
assert(rr_ == [{"first":1}, {"second":2}])
else:
assert False, "unexpected id %s" % rr['id']

Expand Down
48 changes: 33 additions & 15 deletions test/nginx-tnt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,54 @@ WORK_DIR=$PWD/test
NGINX_PREFIX=$PWD/test-root
NGINX="$PWD/nginx/objs/nginx -p $NGINX_PREFIX"

cleanup()
{
`$NGINX -s stop`

rm -f $WORK_DIR/*.xlog $WORK_DIR/*.snap >/dev/null

for job in `jobs -p`; do
kill -s TERM $job
done
for job in `jobs -p`; do
wait $job
done

echo '[+] Done.'
}
trap cleanup EXIT

rm -f $WORK_DIR/*.xlog $WORK_DIR/*.snap >/dev/null

## Env
if [ -e $NGINX_PREFIX/logs/nginx.pid ]; then
`$NGINX -s stop` 2> /dev/null
fi
`$NGINX`

cd $WORK_DIR 1> /dev/null
tarantool test.lua 2> /dev/null &
tarantool test.lua > /dev/null &
cd - 1> /dev/null
sleep 1
sleep 2

## Test
echo "[+] Testing ..."
for i in {1..50}; do

## Tests
for i in {1..10}; do
echo "[+] try: $i"
$WORK_DIR/client.py 1> /dev/null || (
echo "[-] $WORK_DIR/client.py failed, at: $i" && exit 1
echo "[-] $WORK_DIR/client.py failed" && exit 1
)
done

## Clean up
`$NGINX -s stop`

rm -f $WORK_DIR/*.xlog $WORK_DIR/*.snap >/dev/null
for job in `jobs -p`; do
kill -s TERM $job
clients_pids=
for i in {1..3}; do
`$WORK_DIR/client.py 1> /dev/null || (
echo "[-] $WORK_DIR/client.py failed" && exit 1
)` &
clients_pids="$clients_pids $!"
done
for job in `jobs -p`; do
for job in $clients_pids; do
wait $job
done

echo "[+] OK"

exit 0
26 changes: 18 additions & 8 deletions third_party/tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ enum tp_type {

/* header */
enum tp_header_key_t {
TP_CODE = 0x00,
TP_SYNC = 0x01
TP_CODE = 0x00,
TP_SYNC = 0x01,
TP_SERVER_ID = 0x02,
TP_LSN = 0x03,
TP_TIMESTAMP = 0x04,
TP_SCHEMA_ID = 0x05
};

/* request body */
Expand All @@ -70,17 +74,16 @@ enum tp_body_key_t {
TP_LIMIT = 0x12,
TP_OFFSET = 0x13,
TP_ITERATOR = 0x14,
TP_INDEX_BASE = 0x15,
TP_KEY = 0x20,
TP_TUPLE = 0x21,
TP_FUNCTION = 0x22,
TP_USERNAME = 0x23,
TP_EXPRESSION = 0x27,
TP_SERVER_ID = 0x02,
TP_LSN = 0x03,
TP_TIMESTAMP = 0x04,
TP_SERVER_UUID = 0x24,
TP_CLUSTER_UUID = 0x25,
TP_VCLOCK = 0x26
TP_VCLOCK = 0x26,
TP_EXPRESSION = 0x27,
TP_OPS = 0x28
};

/* response body */
Expand Down Expand Up @@ -195,6 +198,7 @@ struct tpresponse {
const char *buf; /* points to beginning of buffer */
uint32_t code; /* response code (0 is success, or errno if not) */
uint32_t sync; /* synchronization id */
uint32_t schema_id; /* schema id */
const char *error; /* error message (NULL if not present) */
const char *error_end; /* end of error message (NULL if not present) */
const char *data; /* tuple data (NULL if not present) */
Expand Down Expand Up @@ -1738,8 +1742,14 @@ tp_reply(struct tpresponse *r, const char * const buf, size_t size)
return -1;
r->code = mp_decode_uint(&p);
break;
case TP_SCHEMA_ID:
if (mp_typeof(*p) != MP_UINT)
return -1;
r->schema_id = mp_decode_uint(&p);
break;
default:
return -1;
mp_next(&p);
break;
}
r->bitmap |= (1ULL << key);
}
Expand Down

0 comments on commit 22fe3ee

Please sign in to comment.