Skip to content

Commit b155500

Browse files
committed
Add random/boolean tests
closes gh-87, closes gh-90
1 parent 4b9d897 commit b155500

File tree

6 files changed

+118
-42
lines changed

6 files changed

+118
-42
lines changed

src/tarantool_msgpack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void php_mp_pack(smart_string *str, zval *val) {
189189
break;
190190
case IS_TRUE:
191191
php_mp_pack_bool(str, 1);
192+
break;
192193
case IS_FALSE:
193194
php_mp_pack_bool(str, 0);
194195
break;

test/DMLTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ public function test_11_update_error() {
223223
}
224224

225225
public function test_12_call() {
226+
$result = self::$tarantool->call("test_6", array(true, false, false));
227+
$this->assertEquals(array(array(true), array(false), array(false)), $result);
226228
$this->assertEquals(
227-
self::$tarantool->call("test_2"),
228229
array(
229230
'0' => array(
230231
'0' => array('k1' => 'v2', 'k2' => 'v')
231232
)
232-
)
233+
),
234+
self::$tarantool->call("test_2")
233235
);
234236
$this->assertEquals(
235237
self::$tarantool->call("test_3", array(3, 4)), array('0' => array('0' => 7)));

test/RandomTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
function generateRandomString($length = 10) {
4+
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5+
$charactersLength = strlen($characters);
6+
$randomString = '';
7+
for ($i = 0; $i < $length; $i++) {
8+
$randomString .= $characters[rand(0, $charactersLength - 1)];
9+
}
10+
return $randomString;
11+
}
12+
13+
class RandomTest extends PHPUnit_Framework_TestCase
14+
{
15+
protected static $tarantool;
16+
17+
public static function setUpBeforeClass() {
18+
self::$tarantool = new Tarantool('localhost', getenv('PRIMARY_PORT'));
19+
self::$tarantool->authenticate('test', 'test');
20+
self::$tarantool->ping();
21+
}
22+
23+
public function test_01_random_big_response() {
24+
for ($i = 5000; $i < 100000; $i += 1000) {
25+
$request = "do return '" . generateRandomString($i) . "' end";
26+
self::$tarantool->evaluate($request);
27+
}
28+
$this->assertTrue(True);
29+
}
30+
31+
public function test_02_very_big_response() {
32+
$request = "do return '" . str_repeat('x', 1024 * 1024 * 10) . "' end";
33+
self::$tarantool->evaluate($request);
34+
$this->assertTrue(True);
35+
}
36+
37+
public function test_03_another_big_response() {
38+
for ($i = 100; $i <= 5200; $i += 100) {
39+
$result = self::$tarantool->call('test_5', array($i));
40+
$this->assertEquals($i, count($result));
41+
}
42+
}
43+
}

test/shared/box.lua

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env tarantool
22

3-
os = require('os')
3+
local os = require('os')
4+
local fun = require('fun')
5+
local log = require('log')
6+
local json = require('json')
7+
48
require('console').listen(os.getenv('ADMIN_PORT'))
59
box.cfg{
610
listen = os.getenv('PRIMARY_PORT'),
@@ -9,54 +13,67 @@ box.cfg{
913
slab_alloc_arena = 0.2
1014
}
1115

12-
lp = {
13-
test = 'test',
14-
test_empty = '',
15-
test_big = '123456789012345678901234567890123456789012345678901234567890' -- '1234567890' * 6
16-
}
17-
18-
for k, v in pairs(lp) do
19-
if #box.space._user.index.name:select{k} == 0 then
20-
box.schema.user.create(k, { password = v })
21-
end
22-
end
23-
24-
box.schema.user.grant('test', 'read,write,execute', 'universe', nil, {if_not_exists=true})
25-
26-
if not box.space.test then
27-
local test = box.schema.space.create('test')
28-
test:create_index('primary', {type = 'TREE', unique = true, parts = {1, 'NUM'}})
29-
test:create_index('secondary', {type = 'TREE', unique = false, parts = {2, 'NUM', 3, 'STR'}})
30-
end
16+
box.once('init', function()
17+
box.schema.user.create('test', { password = 'test' })
18+
box.schema.user.create('test_empty', { password = '' })
19+
box.schema.user.create('test_big', {
20+
password = '123456789012345678901234567890123456789012345678901234567890'
21+
})
22+
box.schema.user.grant('test', 'read,write,execute', 'universe')
3123

32-
if not box.space.msgpack then
33-
local msgpack = box.schema.space.create('msgpack')
34-
msgpack:create_index('primary', {parts = {1, 'NUM'}})
35-
box.schema.user.grant('test', 'read,write', 'space', 'msgpack')
36-
msgpack:insert{1, 'float as key', {[2.7] = {1, 2, 3}}}
37-
msgpack:insert{2, 'array as key', {[{2, 7}] = {1, 2, 3}}}
38-
msgpack:insert{3, 'array with float key as key', {[{[2.7] = 3, [7] = 7}] = {1, 2, 3}}}
39-
msgpack:insert{6, 'array with string key as key', {['megusta'] = {1, 2, 3}}}
40-
end
24+
local space = box.schema.space.create('test')
25+
space:create_index('primary', {
26+
type = 'TREE',
27+
unique = true,
28+
parts = {1, 'NUM'}
29+
})
30+
space:create_index('secondary', {
31+
type = 'TREE',
32+
unique = false,
33+
parts = {2, 'NUM', 3, 'STR'}
34+
})
35+
local space = box.schema.space.create('msgpack')
36+
space:create_index('primary', {
37+
parts = {1, 'NUM'}
38+
})
39+
space:insert{1, 'float as key', {
40+
[2.7] = {1, 2, 3}
41+
}}
42+
space:insert{2, 'array as key', {
43+
[{2, 7}] = {1, 2, 3}
44+
}}
45+
space:insert{3, 'array with float key as key', {
46+
[{
47+
[2.7] = 3,
48+
[7] = 7
49+
}] = {1, 2, 3}
50+
}}
51+
space:insert{6, 'array with string key as key', {
52+
['megusta'] = {1, 2, 3}
53+
}}
54+
end)
4155

4256
function test_1()
4357
return true, {
44-
c= {
45-
['106']= {1, 1428578535},
46-
['2']= {1, 1428578535}
58+
c = {
59+
['106'] = {1, 1428578535},
60+
['2'] = {1, 1428578535}
4761
},
48-
pc= {
49-
['106']= {1, 1428578535, 9243},
50-
['2']= {1, 1428578535, 9243}
62+
pc = {
63+
['106'] = {1, 1428578535, 9243},
64+
['2'] = {1, 1428578535, 9243}
5165
},
52-
s= {1, 1428578535},
53-
u= 1428578535,
54-
v= {}
66+
s = {1, 1428578535},
67+
u = 1428578535,
68+
v = {}
5569
}, true
5670
end
5771

5872
function test_2()
59-
return { k2= 'v', k1= 'v2'}
73+
return {
74+
k2 = 'v',
75+
k1 = 'v2'
76+
}
6077
end
6178

6279
function test_3(x, y)
@@ -65,6 +82,17 @@ end
6582

6683
function test_4(...)
6784
local args = {...}
68-
require('log').info('%s', require('yaml').encode(args))
85+
log.info('%s', json.encode(args))
6986
return 2
7087
end
88+
89+
function test_5(count)
90+
log.info('duplicating %d arrays', count)
91+
local rv = fun.duplicate{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}:take(count):totable()
92+
log.info('%s', json.encode(rv))
93+
return rv
94+
end
95+
96+
function test_6(...)
97+
return ...
98+
end

test/shared/phpunit_bas.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<file>test/DMLTest.php</file>
1010
<file>test/MockTest.php</file>
1111
<file>test/MsgPackTest.php</file>
12+
<file>test/RandomTest.php</file>
1213
</testsuite>
1314
</testsuites>
1415

test/shared/phpunit_tap.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<file>test/DMLTest.php</file>
1111
<file>test/MockTest.php</file>
1212
<file>test/MsgPackTest.php</file>
13+
<file>test/RandomTest.php</file>
1314
</testsuite>
1415
</testsuites>
1516

0 commit comments

Comments
 (0)