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

Function runNutsDBTestWithMockClock

db_test.go:83–102  ·  view source on GitHub ↗

runNutsDBTestWithMockClock runs a test with a MockClock for deterministic TTL testing. The MockClock is initialized with the current system time in milliseconds. The test function receives both the DB and the MockClock to allow time manipulation.

(t *testing.T, opts *Options, test func(t *testing.T, db *DB, mc ttl.Clock))

Source from the content-addressed store, hash-verified

81// The MockClock is initialized with the current system time in milliseconds.
82// The test function receives both the DB and the MockClock to allow time manipulation.
83func runNutsDBTestWithMockClock(t *testing.T, opts *Options, test func(t *testing.T, db *DB, mc ttl.Clock)) {
84 mc := ttl.NewMockClock(time.Now().UnixMilli())
85 if opts == nil {
86 defaultOpts := DefaultOptions
87 opts = &defaultOpts
88 }
89 if opts.Dir == "" {
90 opts.Dir = filepath.Join(t.TempDir(), "nutsdb-test")
91 }
92 opts.TTLConfig.EnableTimingWheel = false
93 defer removeDir(opts.Dir)
94 db, err := Open(*opts)
95 require.NoError(t, err)
96 db.ttlService.SetClock(mc)
97
98 test(t, db, mc)
99 if !db.IsClose() {
100 require.NoError(t, db.Close())
101 }
102}
103
104func runNutsDBTestWithWatch(t *testing.T, test func(t *testing.T, db *DB)) {
105 option := DefaultOptions

Callers 15

TestDB_CheckListExpiredFunction · 0.85
TestTx_ExpiredDeletionFunction · 0.85
TestTx_GetMaxOrMinKeyFunction · 0.85
TestTx_ValueLenFunction · 0.85
TestTx_GetSetFunction · 0.85
TestTx_GetTTLAndPersistFunction · 0.85
TestTx_HasFunction · 0.85
TestTx_RecordExpiredFunction · 0.85

Calls 6

NewMockClockFunction · 0.92
removeDirFunction · 0.85
OpenFunction · 0.85
IsCloseMethod · 0.80
CloseMethod · 0.65
SetClockMethod · 0.45

Tested by

no test coverage detected