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))
| 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. |
| 83 | func 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 | |
| 104 | func runNutsDBTestWithWatch(t *testing.T, test func(t *testing.T, db *DB)) { |
| 105 | option := DefaultOptions |
no test coverage detected