Skip to content

Commit a2234b4

Browse files
Memory core testing (#4710)
* Added zh-cn documents * table lock * table lock * table lock * table lock * table lock * table lock * table lock * table lock * table lock * fixed_pool.cpp and table.cpp Co-authored-by: tianfenghan <[email protected]>
1 parent b29bef2 commit a2234b4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

core-tests/src/memory/fixed_pool.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "test_core.h"
2121
#include "swoole_memory.h"
22+
#include "swoole_util.h"
2223

2324
using namespace std;
2425

@@ -47,6 +48,16 @@ TEST(fixed_pool, alloc) {
4748
pool->free(mem);
4849
}
4950
}
50-
pool->debug(2);
51+
pool->debug(1);
5152
delete pool;
5253
}
54+
55+
TEST(fixed_pool, realloc) {
56+
void *memory = sw_shm_malloc(1024);
57+
void *new_memory = sw_shm_realloc(memory, 2048);
58+
ON_SCOPE_EXIT {
59+
sw_shm_free(new_memory);
60+
};
61+
ASSERT_NE(new_memory, nullptr);
62+
63+
}

core-tests/src/memory/table.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,25 @@ TEST(table, get_value) {
308308
row->get_value(column_id, &lval);
309309
ASSERT_EQ(lval, 0);
310310
}
311+
312+
TEST(table, lock) {
313+
table_t table(test_table_size);
314+
create_table(table);
315+
auto ptr = table.ptr();
316+
317+
std::string key("php");
318+
TableRow *_rowlock = nullptr;
319+
320+
for (int i = 0; i <= 3; i++) {
321+
std::thread t([&]() {
322+
TableRow *row = ptr->get(key.c_str(), key.length(), &_rowlock);
323+
TableColumn *column_name = ptr->get_column("name");
324+
char *str = nullptr;
325+
TableStringLength len = 0;
326+
row->get_value(column_name, &str, &len);
327+
ASSERT_STREQ(str, "php");
328+
});
329+
t.join();
330+
}
331+
_rowlock->unlock();
332+
}

0 commit comments

Comments
 (0)