From 483de7aea67b8194663e560b2d95c75a1b50df4f Mon Sep 17 00:00:00 2001 From: Torrey Payne <11740989+torreypayne@users.noreply.github.com> Date: Mon, 12 Oct 2026 19:52:51 +0000 Subject: [PATCH] test(spanner): add queue acceptance tests --- acceptance/data/fixtures.rb | 11 ++++ .../acceptance/spanner/client/queues_test.rb | 59 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 google-cloud-spanner/acceptance/spanner/client/queues_test.rb diff --git a/acceptance/data/fixtures.rb b/acceptance/data/fixtures.rb index 0cdf4ae5..df35979d 100644 --- a/acceptance/data/fixtures.rb +++ b/acceptance/data/fixtures.rb @@ -196,6 +196,17 @@ def items_ddl_statement ITEMS end + # Not part of schema_ddl_statements: queues need an Enterprise edition + # instance, and the emulator doesn't support them yet. + def queue_ddl_statement + <<~QUEUE + CREATE QUEUE IF NOT EXISTS TestQueue ( + Id INT64 NOT NULL, + Payload BYTES(MAX) NOT NULL + ) PRIMARY KEY (Id) + QUEUE + end + def schema_pg_ddl_statements [ stuff_pg_ddl_statement, diff --git a/google-cloud-spanner/acceptance/spanner/client/queues_test.rb b/google-cloud-spanner/acceptance/spanner/client/queues_test.rb new file mode 100644 index 00000000..f72f3faa --- /dev/null +++ b/google-cloud-spanner/acceptance/spanner/client/queues_test.rb @@ -0,0 +1,59 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "spanner_helper" + +# An ack without ignore_not_found fails with NOT_FOUND unless the message +# exists, so a successful ack also shows that the send landed. +describe "Spanner Client Queues", :queues, :spanner do + let(:db) { spanner_client } + + before do + skip "Cloud Spanner Emulator does not yet support Queues (Send & Ack)" if emulator_enabled? + + # Created once per run, in the per-run test database. + $spanner_test_queue_created ||= begin + db_job = db.database.update statements: [queue_ddl_statement] + db_job.wait_until_done! + raise GRPC::BadStatus.new(db_job.error.code, db_job.error.message) if db_job.error? + true + end + end + + it "sends and acks messages with Client#commit" do + commit_time = db.commit do |c| + c.send_message "TestQueue", 1, StringIO.new("payload1") + c.send_message "TestQueue", 2, StringIO.new("payload2") + end + _(commit_time).must_be_kind_of Time + + commit_time = db.commit do |c| + c.ack_message "TestQueue", 1 + c.ack_message "TestQueue", 2 + end + _(commit_time).must_be_kind_of Time + end + + it "sends and acks a message with Client#transaction" do + commit_time = db.transaction do |tx| + tx.send_message "TestQueue", 3, StringIO.new("payload3") + end + _(commit_time).must_be_kind_of Time + + commit_time = db.transaction do |tx| + tx.ack_message "TestQueue", 3 + end + _(commit_time).must_be_kind_of Time + end +end