From 08e72b83ab775db99147c0dec5e17a0170494597 Mon Sep 17 00:00:00 2001 From: Randy <857271370@qq.com> Date: Wed, 7 Oct 2026 16:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20verify=20Lua=20function=20t?= =?UTF-8?q?ransforms=20across=20backends?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++++++- internal/workload/lua.go | 7 +++++-- tests/integration/semantics_test.go | 30 ++++++++++++++--------------- versions.json | 6 +++--- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c76a02da..453a2c5b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,14 @@ Coverage includes discovery through every node, direct owner connections, typed CRUD and Lua transformations, independent persistence checks, same-Store calls containing many records, slice preflight and per-record validation, typed Scan filters and include/exclude projections, cross-owner continuation, Native response evidence, cancellation, owner restart, directory convergence and persistent client recovery. -Lua tests cover missing and existing documents, explicit and implicit decisions, first creation, and concurrent read-modify-write through both owners. Missing records and missing backend targets have distinct outcomes; empty scans succeed and complete HTTP 404 responses retain Native completion evidence. Separate multi-process tests verify independent single-record callers. +Lua source returns one function receiving the current and incoming documents as +ordinary tables. Tests cover object replacements, explicit keep/delete/reject +actions, first creation, and concurrent read-modify-write through both owners. +Nil, missing or multiple callback results return INVALID_ARGUMENT, including a +callback that returns a missing current document. Missing records and missing +backend targets have distinct outcomes; empty scans succeed and complete HTTP +404 responses retain Native completion evidence. Separate multi-process tests +verify independent single-record callers. One-RPC reads deliver 64 MiB and 256 MiB across 1024 and 4096 distinct documents while checking bounded result credits and sampled owner RSS. Interrupted streams retain confirmed record outcomes; unconfirmed mutations remain indeterminate. @@ -97,6 +104,8 @@ MongoDB request uses a snapshot transaction with one read, revision computation, replacement and majority commit. Each native Search request uses one real-time read and a write conditioned on its observed sequence number and primary term. The SDK sends one Lua `AtomicTransform` per request with the same computation. +The function updates `current.revision = 1 - current.revision` and returns the +current document; existing BSON int32 revision fields retain their width. Fixture documents are identical on both paths; Weir adds no document metadata. Repeat with `-backend-batch-limit 1` to disable server aggregation. Keep other diff --git a/internal/workload/lua.go b/internal/workload/lua.go index ae1437d1..31727278 100644 --- a/internal/workload/lua.go +++ b/internal/workload/lua.go @@ -19,8 +19,11 @@ import ( ) func (d *Dataset) luaSource() string { - // The fixture stores BSON int32 and JSON 0/1, both read as Lua int32. - return `return weir.replace(weir.set(current, "revision", weir.sub(weir.i32("1"), weir.get(current, "revision"))))` + // Reassigning the existing revision field preserves its BSON int32 width. + return `return function(current) + current.revision = 1 - current.revision + return current +end` } // The native path performs the same single-record read-modify-write, without diff --git a/tests/integration/semantics_test.go b/tests/integration/semantics_test.go index 77102e2c..cf7a6ce3 100644 --- a/tests/integration/semantics_test.go +++ b/tests/integration/semantics_test.go @@ -21,15 +21,16 @@ func (s *system) testLuaSemantics(t *testing.T, backend *backendData) { n int64 failure weir.FailureCode }{ - {name: "merge", source: "return weir.replace(weir.merge(current,input))", present: true, n: 42}, - {name: "implicit_replace", source: "return weir.merge(current,input)", present: true, n: 42}, - {name: "keep", source: "return weir.keep()"}, - {name: "delete", source: "return weir.delete()"}, - {name: "reject", source: "return weir.reject(\"rejected\")", failure: weir.FailurePreconditionFailed}, - {name: "no_return", source: "local v = current"}, - {name: "nil_return", source: "return nil"}, - {name: "current", source: "return current"}, - {name: "invalid", source: "return )", failure: weir.FailureInvalidArgument}, + {name: "merge", source: "return function(current, incoming) current = current or weir.object(); for key, item in pairs(incoming) do current[key] = item end; return current end", present: true, n: 42}, + {name: "replace", source: "return function(_, incoming) return incoming end", present: true, n: 42}, + {name: "keep", source: "return function() return weir.keep() end"}, + {name: "delete", source: "return function() return weir.delete() end"}, + {name: "reject", source: "return function() return weir.reject(\"rejected\") end", failure: weir.FailurePreconditionFailed}, + {name: "no_return", source: "return function(current) local v = current end", failure: weir.FailureInvalidArgument}, + {name: "nil_return", source: "return function() return nil end", failure: weir.FailureInvalidArgument}, + {name: "multiple_return", source: "return function() return {}, weir.keep() end", failure: weir.FailureInvalidArgument}, + {name: "current", source: "return function(current) return current end"}, + {name: "invalid", source: "return function() return ) end", failure: weir.FailureInvalidArgument}, } for _, existing := range []bool{false, true} { for _, tc := range cases { @@ -78,12 +79,11 @@ func (s *system) testConcurrentLuaCreate(t *testing.T, backend *backendData) { t.Helper() const id = "lua_cross_owner_counter" const iterations = 4 - one := "weir.i64(\"1\")" - if backend.name == "search" { - one = "weir.i32(\"1\")" - } - source := []byte(`if weir.kind(current)=="missing" then return weir.replace(input) end -return weir.replace(weir.set(current,"n",weir.add(weir.get(current,"n"),` + one + `)))`) + source := []byte(`return function(current, incoming) + if current == nil then return incoming end + current.n = current.n + 1 + return current +end`) start := make(chan struct{}) finished := make(chan error, 2) for _, node := range s.cluster.Nodes[:2] { diff --git a/versions.json b/versions.json index efb76296..0c17e7fe 100644 --- a/versions.json +++ b/versions.json @@ -2,12 +2,12 @@ "go": "1.27.1", "sdk": "v0.9.0", "protocol": "v0.7.0", - "weir_source": "c00fcec963326100f6156e183bbc074dc7a7d4d7", + "weir_source": "d3ea541143a819d6e839b6ce398221d85a20ce90", "mongodb_version": "8.0.32", "elasticsearch_version": "8.19.22", "elasticsearch_image": "docker.elastic.co/elasticsearch/elasticsearch@sha256:e98f9c3b09beb2fbb9eaf667d602df3f0e00bd3644138b8458dc17ba1a675595", - "weir_version": "v0.1.1-0.20261004162211-c00fcec96332", - "weir_sum": "h1:DowMQvE5uL5fI0iUCLenY/kaFPLr0XHIV6HYnKULr5o=", + "weir_version": "v0.1.1-0.20261007083022-d3ea541143a8", + "weir_sum": "h1:+d+Fs+R1rCYpQHindXtE8cNiMms8mlCJ5fMFWw6GMbw=", "mongodb_image": "mongo@sha256:d0d926f94df099bff534b7ee5b5986458131a22489dfff8664509af0c1e2ca9c", "mongodb_darwin_arm64_url": "https://fastdl.mongodb.org/osx/mongodb-macos-arm64-8.0.32.tgz", "mongodb_darwin_arm64_sha256": "f81cb258434d548dca7244d599c82eb339043d8dedd0b1b807870c9d263117f2",