MCPcopy
hub / github.com/lindb/lindb / TestDatabase_WaitFlushMetaCompleted

Function TestDatabase_WaitFlushMetaCompleted

tsdb/database_test.go:435–473  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

433}
434
435func TestDatabase_WaitFlushMetaCompleted(t *testing.T) {
436 ctrl := gomock.NewController(t)
437 defer ctrl.Finish()
438
439 now := commontimeutil.Now()
440 metaDB := memdb.NewMockMetadataDatabase(ctrl)
441 db := &database{
442 memMetaDB: metaDB,
443 isFlushing: *atomic.NewBool(false),
444 flushCondition: sync.NewCond(&sync.Mutex{}),
445 statistics: metrics.NewDatabaseStatistics("test"),
446 }
447
448 metaDB.EXPECT().Notify(gomock.Any()).DoAndReturn(func(event any) {
449 time.Sleep(100 * time.Millisecond)
450 mn := event.(*memdb.FlushEvent)
451 mn.Callback(nil)
452 })
453 var wait sync.WaitGroup
454 wait.Add(2)
455 ch := make(chan struct{})
456 go func() {
457 ch <- struct{}{}
458 err := db.FlushMeta()
459 assert.NoError(t, err)
460 }()
461 <-ch
462 time.Sleep(10 * time.Millisecond)
463 go func() {
464 db.WaitFlushMetaCompleted()
465 wait.Done()
466 }()
467 go func() {
468 db.WaitFlushMetaCompleted()
469 wait.Done()
470 }()
471 wait.Wait()
472 assert.True(t, commontimeutil.Now()-now >= 100*time.Millisecond.Milliseconds())
473}
474
475func TestDatabase_Drop(t *testing.T) {
476 ctrl := gomock.NewController(t)

Callers

nothing calls this directly

Calls 7

FlushMetaMethod · 0.95
NewDatabaseStatisticsFunction · 0.92
DoneMethod · 0.80
WaitMethod · 0.80
NotifyMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected