From b309d82538a7690e720a1f785f0c2107c38ab1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E=E4=BB=94?= <41766775+huahua132@users.noreply.github.com> Date: Sat, 6 Jan 2024 16:38:14 +0800 Subject: [PATCH] fix word err (#1848) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix word err * fix word err * 增加mongo update 测试 --- lualib/skynet/socket.lua | 2 +- test/testmongodb.lua | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lualib/skynet/socket.lua b/lualib/skynet/socket.lua index b15dd024..e047ffff 100644 --- a/lualib/skynet/socket.lua +++ b/lualib/skynet/socket.lua @@ -154,7 +154,7 @@ socket_message[5] = function(id, _, err) return end if s.callback then - skynet.error("socket: accpet error:", err) + skynet.error("socket: accept error:", err) return end if s.connected then diff --git a/test/testmongodb.lua b/test/testmongodb.lua index 89033e99..662cc305 100644 --- a/test/testmongodb.lua +++ b/test/testmongodb.lua @@ -7,6 +7,11 @@ if port then port = math.tointeger(port) end +host = '127.0.0.1' +port = 27017 +username = "admin" +password = 123456 +db_name = "admin" -- print(host, port, db_name, username, password) local function _create_client() @@ -19,7 +24,7 @@ local function _create_client() ) end -function test_auth() +local function test_auth() local ok, err, ret local c = mongo.client( { @@ -39,7 +44,7 @@ function test_auth() assert(ok and ret and ret.n == 1, err) end -function test_insert_without_index() +local function test_insert_without_index() local ok, err, ret local c = _create_client() local db = c[db_name] @@ -54,7 +59,7 @@ function test_insert_without_index() assert(ok and ret and ret.n == 1, err) end -function test_insert_with_index() +local function test_insert_with_index() local ok, err, ret local c = _create_client() local db = c[db_name] @@ -71,7 +76,7 @@ function test_insert_with_index() assert(ok == false and string.find(err, "duplicate key error")) end -function test_find_and_remove() +local function test_find_and_remove() local ok, err, ret local c = _create_client() local db = c[db_name] @@ -117,7 +122,7 @@ function test_find_and_remove() assert(ret == nil) end -function test_runcommand() +local function test_runcommand() local ok, err, ret local c = _create_client() local db = c[db_name] @@ -148,7 +153,7 @@ function test_runcommand() assert(ret and ret.cursor.firstBatch[1].test_key2_total == 6) end -function test_expire_index() +local function test_expire_index() local ok, err, ret local c = _create_client() local db = c[db_name] @@ -221,6 +226,26 @@ local function test_safe_batch_delete() assert((length - del_num) == ret:count(), "test safe batch delete failed") end +local function test_safe_update() + local ok, err, ret + local c = _create_client() + local db = c[db_name] + + db.testcoll:drop() + + db.testcoll:safe_insert({test_key = 100, test_value = "hello mongo"}) + + db.testcoll:ensureIndex({test_key = 1}, {unique = true, name = "test_key_index"}) + + local query = {test_key = 100} + local update = {test_value = "hi mongo"} + ok, err = db.testcoll:safe_update(query, {['$set'] = update}) + assert(ok, err) + + ret = db.testcoll:findOne(query) + assert(ret.test_value == "hi mongo") +end + skynet.start(function() if username then print("Test auth") @@ -240,5 +265,7 @@ skynet.start(function() test_safe_batch_insert() print("test safe batch delete") test_safe_batch_delete() + print("test_safe_update") + test_safe_update() print("mongodb test finish."); end)