Skip to content

Commit 7224417

Browse files
committed
add test cases for UpdateClusterFinalizedHeight
1 parent d1ad4e9 commit 7224417

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

storage/operation/cluster_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,51 @@ func Test_RetrieveClusterFinalizedHeight(t *testing.T) {
172172
assert.Equal(t, clusterFinalizedHeights[i], actual)
173173
}
174174
})
175+
176+
t.Run("update to non-sequential finalized height returns error", func(t *testing.T) {
177+
// Use a different cluster ID to avoid conflicts with other tests
178+
testClusterID := flow.ChainID("test-cluster-non-sequential")
179+
180+
// First bootstrap a cluster with height 20
181+
err := unittest.WithLock(t, lockManager, storage.LockInsertOrFinalizeClusterBlock, func(lctx lockctx.Context) error {
182+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
183+
return operation.BootstrapClusterFinalizedHeight(lctx, rw, testClusterID, 20)
184+
})
185+
})
186+
require.NoError(t, err)
187+
188+
// Try to update to a non-sequential height (should fail)
189+
err = unittest.WithLock(t, lockManager, storage.LockInsertOrFinalizeClusterBlock, func(lctx lockctx.Context) error {
190+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
191+
return operation.UpdateClusterFinalizedHeight(lctx, rw, testClusterID, 25) // Should be 21, not 25
192+
})
193+
})
194+
require.Error(t, err)
195+
assert.Contains(t, err.Error(), "finalization isn't sequential")
196+
})
197+
198+
t.Run("bootstrap on non-empty key returns error", func(t *testing.T) {
199+
// Use a different cluster ID to avoid conflicts with other tests
200+
testClusterID := flow.ChainID("test-cluster-bootstrap-error")
201+
202+
// First bootstrap a cluster with height 30
203+
err := unittest.WithLock(t, lockManager, storage.LockInsertOrFinalizeClusterBlock, func(lctx lockctx.Context) error {
204+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
205+
return operation.BootstrapClusterFinalizedHeight(lctx, rw, testClusterID, 30)
206+
})
207+
})
208+
require.NoError(t, err)
209+
210+
// Try to bootstrap again (should fail)
211+
err = unittest.WithLock(t, lockManager, storage.LockInsertOrFinalizeClusterBlock, func(lctx lockctx.Context) error {
212+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
213+
return operation.BootstrapClusterFinalizedHeight(lctx, rw, testClusterID, 35)
214+
})
215+
})
216+
require.Error(t, err)
217+
assert.Contains(t, err.Error(), "finalized height for cluster")
218+
assert.Contains(t, err.Error(), "already initialized")
219+
})
175220
})
176221
}
177222

0 commit comments

Comments
 (0)