This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch auto-delete-3
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/auto-delete-3 by this push:
     new 0ad5b2e2b drop_seq shard split integration test
0ad5b2e2b is described below

commit 0ad5b2e2b0c59f0ee8e96057e710ee82582d39d9
Author: Robert Newson <[email protected]>
AuthorDate: Wed May 21 15:43:56 2025 +0100

    drop_seq shard split integration test
---
 src/fabric/src/fabric_drop_seq.erl   |  1 -
 test/elixir/test/config/suite.elixir |  3 +-
 test/elixir/test/drop_seq_test.exs   | 65 +++++++++++++++++++++++++++++++++---
 3 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/src/fabric/src/fabric_drop_seq.erl 
b/src/fabric/src/fabric_drop_seq.erl
index 928a1bdb3..50556008c 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -97,7 +97,6 @@ go_int(Shards0, UuidFetcher, PeerCheckpoints0, 
ShardSyncHistory) ->
     PeerCheckpoints1 = crossref(PeerCheckpoints0, ShardSyncHistory),
     PeerCheckpoints2 = substitute_splits(Shards1, UuidFetcher, 
PeerCheckpoints1),
     DropSeqs = calculate_drop_seqs(PeerCheckpoints2, ShardSyncHistory),
-
     {Shards1, DropSeqs}.
 
 -spec calculate_drop_seqs(peer_checkpoints(), shard_sync_history()) ->
diff --git a/test/elixir/test/config/suite.elixir 
b/test/elixir/test/config/suite.elixir
index c7638b7a6..f283096c2 100644
--- a/test/elixir/test/config/suite.elixir
+++ b/test/elixir/test/config/suite.elixir
@@ -213,7 +213,8 @@
   ],
   "DropSeqTest": [
     "peer checkpoint - mrview",
-    "peer checkpoint - custom"
+    "peer checkpoint - custom",
+    "peer checkpoint - shard split"
   ],
   "ErlangViewsTest": [
     "Erlang map function",
diff --git a/test/elixir/test/drop_seq_test.exs 
b/test/elixir/test/drop_seq_test.exs
index 85ee3f200..c62bfa647 100644
--- a/test/elixir/test/drop_seq_test.exs
+++ b/test/elixir/test/drop_seq_test.exs
@@ -95,15 +95,58 @@ defmodule DropSeqTest do
     checkpoint_test_helper(context[:db_name], update_checkpoint_fn, 
update_checkpoint_fn)
   end
 
+  @tag :with_db
+  test "peer checkpoint - shard split", context do
+    db_name = context[:db_name]
+    peer_checkpoint_id = "_local/peer-checkpoint-foo"
+
+    create_checkpoint_fn = fn ->
+      resp = Couch.get("/#{db_name}")
+      assert resp.status_code == 200
+      update_seq = resp.body["update_seq"]
+
+      resp = Couch.put("/#{db_name}/#{peer_checkpoint_id}", body: %{
+        update_seq: update_seq
+      })
+      assert resp.status_code == 201
+
+      resp = Couch.get("/#{db_name}/_shards")
+      assert resp.status_code == 200
+      ranges = Map.keys(resp.body["shards"])
+      Enum.each(ranges, fn r ->
+        resp = Couch.post("/_reshard/jobs", body: %{
+          type: "split",
+          db: db_name,
+          range: r
+        })
+        assert resp.status_code == 201
+      end)
+      wait_for_reshard_jobs_to_complete()
+    end
+
+    update_checkpoint_fn = fn ->
+      resp = Couch.get("/#{db_name}")
+      assert resp.status_code == 200
+      update_seq = resp.body["update_seq"]
+
+      resp = Couch.put("/#{db_name}/#{peer_checkpoint_id}", body: %{
+        update_seq: update_seq
+      })
+      assert resp.status_code == 201
+    end
+
+    checkpoint_test_helper(context[:db_name], create_checkpoint_fn, 
update_checkpoint_fn)
+  end
+
   defp checkpoint_test_helper(db_name, create_checkpoint_fn, 
update_checkpoint_fn) do
     doc_id = "testdoc"
 
-    assert get_drop_count(db_name) == 0
+    drop_count = get_drop_count(db_name)
     drop_seq = update_drop_seq(db_name)
 
     # create something that will create a peer checkpoint
     create_checkpoint_fn.()
-    assert get_drop_count(db_name) == 0
+    assert get_drop_count(db_name) == drop_count
 
     # create a document
     resp = Couch.put("/#{db_name}/#{doc_id}", body: %{})
@@ -116,7 +159,7 @@ defmodule DropSeqTest do
 
     # wait for drop seq to change
     wait_for_drop_seq_change(db_name, drop_seq, update_checkpoint_fn)
-    assert get_drop_count(db_name) == 0
+    assert get_drop_count(db_name) == drop_count
 
     # confirm deleted doc is still in _changes response
     resp = Couch.get("/#{db_name}/_changes")
@@ -130,7 +173,7 @@ defmodule DropSeqTest do
     resp = Couch.get("/#{db_name}/_changes")
     assert resp.status_code == 200
     assert !Enum.member?(get_ids(resp), doc_id)
-    assert get_drop_count(db_name) == 1
+    assert get_drop_count(db_name) == drop_count + 1
   end
 
   defp wait_for_drop_seq_change(db_name, previous_drop_seq, 
update_checkpoint_fn) do
@@ -145,6 +188,20 @@ defmodule DropSeqTest do
     )
   end
 
+  defp wait_for_reshard_jobs_to_complete() do
+    retry_until(
+      fn ->
+        resp = Couch.get("/_reshard/jobs")
+        assert resp.status_code == 200
+        Enum.all?(resp.body["jobs"], fn job ->
+          job["job_state"] == "completed"
+        end)
+      end,
+      200,
+      10_000
+    )
+  end
+
   defp update_drop_seq(db_name) do
     resp = Couch.post("/#{db_name}/_update_drop_seq")
     assert resp.status_code == 201

Reply via email to