Skip to content

Updated PHPUnit to version 7 + gh-24 + gh-42 + gh-85 + gh-83 + gh-71 #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Makefile.in
/config.nice
/config.status
/config.sub
/configure.ac
/configure.in
/libtool
/ltmain.sh
Expand Down
8 changes: 4 additions & 4 deletions lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ def execute_no_reconnect(self, command):
if not command:
return
cmd = command.replace('\n', ' ') + '\n'
self.socket.sendall(cmd)
self.socket.sendall(cmd.encode())

bufsiz = 4096
res = ""
res = b''

while True:
buf = self.socket.recv(bufsiz)
if not buf:
break
res = res + buf
if (res.rfind("\n...\n") >= 0 or res.rfind("\r\n...\r\n") >= 0):
if (res.rfind(b'\n...\n') >= 0 or res.rfind(b'\r\n...\r\n') >= 0):
break

return yaml.load(res)
Expand Down Expand Up @@ -245,7 +245,7 @@ def start(self):
self.generate_configuration()
if self.script:
shutil.copy(self.script, self.script_dst)
os.chmod(self.script_dst, 0777)
os.chmod(self.script_dst, 511)
Copy link
Member

Choose a reason for hiding this comment

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

It is better to use 0o777, should work with python2 and python3 both.

args = self.prepare_args()
self.process = subprocess.Popen(args,
cwd = self.vardir,
Expand Down
1 change: 1 addition & 0 deletions src/tarantool.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ static zend_object *tarantool_create(zend_class_entry *entry) {
obj = (tarantool_object *)pecalloc(1, sizeof(tarantool_object) +
sizeof(zval) * (entry->default_properties_count - 1), 0);
zend_object_std_init(&obj->zo, entry);
object_properties_init(&obj->zo, entry);
obj->zo.handlers = &tarantool_obj_handlers;

return &obj->zo;
Expand Down
115 changes: 57 additions & 58 deletions src/tarantool_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,41 @@
#define MUR_SEED 13
#include "third_party/msgpuck.h"

int mh_indexcmp_eq(
const struct schema_index_value **lval,
const struct schema_index_value **rval,
void *arg
) {
(void )arg;
if ((*lval)->key.id_len != (*rval)->key.id_len)
return 0;
return !memcmp((*lval)->key.id, (*rval)->key.id, (*rval)->key.id_len);
}
#define MH_DEFINE_CMPFUNC(NAME, TYPE) \
Copy link
Member

Choose a reason for hiding this comment

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

I trying to retain myself from formatting nitpicking, but here the entire block formatted with exceeding 80 symbols limit.

int mh_##NAME##cmp_eq(const TYPE **lval, const TYPE **rval, void *arg) { \
(void *) arg; \
if ((*lval)->key.id_len != (*rval)->key.id_len) \
return 0; \
return !memcmp((*lval)->key.id, (*rval)->key.id, (*rval)->key.id_len); \
} \
\
int mh_##NAME##cmp_key_eq(const struct schema_key *key, const TYPE **val, void *arg) { \
(void *) arg; \
if (key->id_len != (*val)->key.id_len) \
return 0; \
return !memcmp(key->id, (*val)->key.id, key->id_len); \
}
MH_DEFINE_CMPFUNC(field, struct schema_field_value);
MH_DEFINE_CMPFUNC(index, struct schema_index_value);
MH_DEFINE_CMPFUNC(space, struct schema_space_value);
#undef MH_DEFINE_CMPFUNC

int mh_indexcmp_key_eq(
const struct schema_key *key,
const struct schema_index_value **val,
void *arg
) {
(void )arg;
if (key->id_len != (*val)->key.id_len)
return 0;
return !memcmp(key->id, (*val)->key.id, key->id_len);
}
#define mh_arg_t void *

#define mh_eq(a, b, arg) mh_fieldcmp_eq(a, b, arg)
#define mh_eq_key(a, b, arg) mh_fieldcmp_key_eq(a, b, arg)
#define mh_hash(x, arg) PMurHash32(MUR_SEED, (*x)->key.id, (*x)->key.id_len)
#define mh_hash_key(x, arg) PMurHash32(MUR_SEED, (x)->id, (x)->id_len);

#define mh_node_t struct schema_field_value *
#define mh_key_t struct schema_key *

#define MH_CALLOC(x, y) pecalloc((x), (y), 1)
#define MH_FREE(x) pefree((x), 1)

#define mh_name _schema_field
#define MH_SOURCE 1
#include "third_party/mhash.h"

#define mh_arg_t void *

Expand Down Expand Up @@ -79,7 +93,7 @@ schema_index_free(struct mh_schema_index_t *schema) {
do {
struct schema_key key_number = {
(void *)&(ivalue->index_number),
sizeof(uint32_t), 0
sizeof(ivalue->index_number), 0
};
index_slot = mh_schema_index_find(schema, &key_number,
NULL);
Expand All @@ -106,28 +120,6 @@ schema_index_free(struct mh_schema_index_t *schema) {
}
}

int
mh_spacecmp_eq(
const struct schema_space_value **lval,
const struct schema_space_value **rval,
void *arg) {
(void )arg;
if ((*lval)->key.id_len != (*rval)->key.id_len)
return 0;
return !memcmp((*lval)->key.id, (*rval)->key.id, (*rval)->key.id_len);
}

int
mh_spacecmp_key_eq(
const struct schema_key *key,
const struct schema_space_value **val,
void *arg) {
(void )arg;
if (key->id_len != (*val)->key.id_len)
return 0;
return !memcmp(key->id, (*val)->key.id, key->id_len);
}

#define mh_arg_t void *

#define mh_eq(a, b, arg) mh_spacecmp_eq(a, b, arg)
Expand Down Expand Up @@ -158,6 +150,9 @@ schema_space_value_free(const struct schema_space_value *val) {
schema_index_free(val->index_hash);
mh_schema_index_delete(val->index_hash);
}
if (val->schema_hash) {
mh_schema_field_delete(val->schema_hash);
}
}
}

Expand Down Expand Up @@ -263,6 +258,11 @@ parse_schema_space_value(struct schema_space_value *space_string,
goto error;
}
val->field_number = i;
val->key.id = val->field_name;
val->key.id_len = val->field_name_len;
mh_schema_field_put(space_string->schema_hash,
(const struct schema_field_value **)&val,
NULL, NULL);
}
return 0;
error:
Expand Down Expand Up @@ -367,6 +367,7 @@ schema_add_space(
* }
*/
case 6:
space_string->schema_hash = mh_schema_field_new();
if (parse_schema_space_value(space_string, &tuple) < 0)
goto error;
break;
Expand Down Expand Up @@ -590,23 +591,21 @@ tarantool_schema_get_fid_by_string(
struct tarantool_schema *schema_obj, uint32_t sid,
const char *field_name, uint32_t field_name_len
) {
struct mh_schema_space_t *schema = schema_obj->space_hash;
struct schema_key space_key = {
(void *)&sid,
sizeof(uint32_t), 0
};
mh_int_t space_slot = mh_schema_space_find(schema, &space_key, NULL);
if (space_slot == mh_end(schema))
struct mh_schema_space_t *sschema = schema_obj->space_hash;
struct schema_key space_key = { (void *)&sid, sizeof(uint32_t), 0 };
mh_int_t space_slot = mh_schema_space_find(sschema, &space_key, NULL);
if (space_slot == mh_end(sschema))
return -1;
const struct schema_space_value *space = *mh_schema_space_node(schema,
const struct schema_space_value *space = *mh_schema_space_node(sschema,
space_slot);
int i = 0;
for (i = 0; i < space->schema_list_len; ++i) {
struct schema_field_value *val = &space->schema_list[i];
if (strncmp(val->field_name, field_name, field_name_len) == 0)
return val->field_number;
}
return -1;
struct schema_key field_key = { field_name, field_name_len, 0 };
struct mh_schema_field_t *fschema = space->schema_hash;
mh_int_t field_slot = mh_schema_field_find(fschema, &field_key, NULL);
if (field_slot == mh_end(fschema))
return -1;
const struct schema_field_value *field = *mh_schema_field_node(fschema,
field_slot);
return field->field_number;
}

struct tarantool_schema *tarantool_schema_new(int is_persistent) {
Expand Down
14 changes: 8 additions & 6 deletions src/tarantool_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ enum field_type {
};

struct schema_field_value {
uint32_t field_number;
char *field_name;
uint32_t field_name_len;
enum field_type field_type;
struct schema_key key;
uint32_t field_number;
char *field_name;
uint32_t field_name_len;
enum field_type field_type;
};

struct schema_index_value {
struct schema_key key;
uint32_t index_number;
char *index_name;
uint32_t index_name_len;
uint32_t index_number;
struct schema_field_value *index_parts;
uint32_t index_parts_len;
};
Expand All @@ -33,10 +34,11 @@ struct mh_schema_index_t;

struct schema_space_value {
struct schema_key key;
uint32_t space_number;
char *space_name;
uint32_t space_name_len;
uint32_t space_number;
struct mh_schema_index_t *index_hash;
struct mh_schema_field_t *schema_hash;
struct schema_field_value *schema_list;
uint32_t schema_list_len;
};
Expand Down
18 changes: 10 additions & 8 deletions test-run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python

import os
import sys
Expand All @@ -12,6 +12,8 @@

from pprint import pprint

PHPUNIT_PHAR = 'phpunit.phar'

def read_popen(cmd):
path = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
path.wait()
Expand All @@ -22,7 +24,7 @@ def read_popen_config(cmd):
return read_popen(cmd)

def find_php_bin():
path = read_popen('which php').strip()
path = read_popen('which php').strip().decode()
if (path.find('phpenv') != -1):
version = read_popen('phpenv global')
if (version.find('system') != -1):
Expand All @@ -37,7 +39,7 @@ def prepare_env(php_ini):
os.mkdir('var')
shutil.copy('test/shared/phpunit.xml', 'var')
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
test_lib_path = os.path.join(test_dir_path, PHPUNIT_PHAR)
# shutil.copy('test/shared/tarantool.ini', 'var')
shutil.copy(php_ini, 'var')
shutil.copy('modules/tarantool.so', 'var')
Expand All @@ -60,10 +62,10 @@ def main():
try:
shutil.copy('test/shared/phpunit.xml', os.path.join(test_cwd, 'phpunit.xml'))
shutil.copy('modules/tarantool.so', test_cwd)
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
test_lib_path = os.path.join(test_dir_path, PHPUNIT_PHAR)

version = read_popen_config('--version').strip(' \n\t') + '.'
version1 = read_popen_config('--extension-dir').strip(' \n\t')
version = read_popen_config('--version').decode().strip(' \n\t') + '.'
version1 = read_popen_config('--extension-dir').decode().strip(' \n\t')
version += '\n' + ('With' if version1.find('non-zts') == -1 else 'Without') + ' ZTS'
version += '\n' + ('With' if version1.find('no-debug') == -1 else 'Without') + ' Debug'
print('Running against ' + version)
Expand Down Expand Up @@ -100,9 +102,9 @@ def main():
cmd = cmd + 'sudo dtruss ' + find_php_bin()
cmd = cmd + ' -c tarantool.ini {0}'.format(test_lib_path)
else:
print find_php_bin()
print(find_php_bin())
cmd = '{0} -c tarantool.ini {1}'.format(find_php_bin(), test_lib_path)
print cmd
print(cmd)

print('Running "%s" with "%s"' % (cmd, php_ini))
proc = subprocess.Popen(cmd, shell=True, cwd=test_cwd)
Expand Down
8 changes: 7 additions & 1 deletion test/AssertTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class AssertTest extends PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class AssertTest extends TestCase
{
protected static $tarantool, $tm;

Expand Down Expand Up @@ -39,6 +42,9 @@ function assert_f()
self::$tarantool->select("test");
}

/**
* @doesNotPerformAssertions
*/
public function test_01_closed_connection() {
for ($i = 0; $i < 20000; $i++) {
try {
Expand Down
9 changes: 7 additions & 2 deletions test/CreateTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class CreateTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

final class CreateTest extends TestCase
{
protected static $port, $tm;

Expand Down Expand Up @@ -34,6 +36,9 @@ public function test_01_create_test_ping_and_close() {
$c->close();
}

/**
* @doesNotPerformAssertions
*/
public function test_01_01_double_disconnect() {
$a = new Tarantool('localhost', self::$port);
$a->disconnect();
Expand All @@ -42,7 +47,7 @@ public function test_01_01_double_disconnect() {

/**
* @expectedException TarantoolException
* @expectedExceptionMessageRegExp /Name or service not known|nodename nor servname provided/
* @expectedExceptionMessageRegExp /Name or service not known|nodename nor servname provided|getaddrinfo/
*/
public function test_02_create_error_host() {
(new Tarantool('very_bad_host'))->connect();
Expand Down
14 changes: 13 additions & 1 deletion test/DMLTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class DMLTest extends PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class DMLTest extends TestCase
{
protected static $tarantool;

Expand Down Expand Up @@ -158,6 +161,9 @@ public function test_06_update() {
$this->assertEquals($result_tuple, $tuple[0]);
}

/**
* @doesNotPerformAssertions
*/
public function test_07_update_no_error() {
self::$tarantool->update("test", 0, array());
}
Expand Down Expand Up @@ -439,6 +445,9 @@ public static function provideIteratorGood() {
];
}

/**
* @doesNotPerformAssertions
*/
public function test_18_01_delete_loop() {
for ($i = 0; $i <= 1000; $i++) {
self::$tarantool->replace("pstring", array("test2" . $i, $i));
Expand All @@ -451,6 +460,9 @@ public function test_18_01_delete_loop() {
gc_collect_cycles();
}

/**
* @doesNotPerformAssertions
*/
public function test_18_02_delete_loop() {
for ($i = 0; $i <= 1000; $i++) {
self::$tarantool->replace("pstring", array("test2" . $i, $i));
Expand Down
Loading