MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestDB_Close_WithMergeInProgress

Function TestDB_Close_WithMergeInProgress

db_test.go:1213–1254  ·  view source on GitHub ↗

TestDB_Close_WithMergeInProgress tests closing database during merge operation

(t *testing.T)

Source from the content-addressed store, hash-verified

1211
1212// TestDB_Close_WithMergeInProgress tests closing database during merge operation
1213func TestDB_Close_WithMergeInProgress(t *testing.T) {
1214 opts := DefaultOptions
1215 opts.Dir = filepath.Join(t.TempDir(), "test-close-merge")
1216 opts.SegmentSize = 1024 // Small segment to trigger merge easily
1217 defer func() { _ = os.RemoveAll(opts.Dir) }()
1218
1219 db, err := Open(opts)
1220 require.NoError(t, err)
1221 require.NotNil(t, db)
1222
1223 bucket := "test_bucket"
1224 err = db.Update(func(tx *Tx) error {
1225 return tx.NewBucket(DataStructureBTree, bucket)
1226 })
1227 require.NoError(t, err)
1228
1229 // Add enough data to potentially trigger merge
1230 for i := 0; i < 100; i++ {
1231 key := testutils.GetTestBytes(i)
1232 val := testutils.GetRandomBytes(100)
1233 err = db.Update(func(tx *Tx) error {
1234 return tx.Put(bucket, key, val, Persistent)
1235 })
1236 require.NoError(t, err)
1237 }
1238
1239 // Try to trigger merge (may or may not actually start)
1240 go func() {
1241 _ = db.Merge()
1242 }()
1243
1244 // Give merge a moment to potentially start
1245 time.Sleep(100 * time.Millisecond)
1246
1247 // Close should handle merge gracefully
1248 err = db.Close()
1249 require.NoError(t, err)
1250
1251 // Verify database is closed
1252 require.True(t, db.IsClose())
1253 require.True(t, db.statusMgr.isClosed())
1254}
1255
1256// TestDB_Close_ResourceCleanup tests that all resources are properly cleaned up
1257func TestDB_Close_ResourceCleanup(t *testing.T) {

Callers

nothing calls this directly

Calls 10

GetTestBytesFunction · 0.92
GetRandomBytesFunction · 0.92
OpenFunction · 0.85
UpdateMethod · 0.80
NewBucketMethod · 0.80
MergeMethod · 0.80
IsCloseMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.45
isClosedMethod · 0.45

Tested by

no test coverage detected