(t *testing.T, spo StorePersistOptions)
| 513 | } |
| 514 | |
| 515 | func testStoreOps(t *testing.T, spo StorePersistOptions) { |
| 516 | tmpDir, _ := ioutil.TempDir("", "mossStore") |
| 517 | defer os.RemoveAll(tmpDir) |
| 518 | |
| 519 | mo := &MergeOperatorStringAppend{Sep: ":"} |
| 520 | |
| 521 | var mu sync.Mutex |
| 522 | counts := map[EventKind]int{} |
| 523 | durations := map[EventKind]time.Duration{} |
| 524 | eventWaiters := map[EventKind]chan bool{} |
| 525 | |
| 526 | co := CollectionOptions{ |
| 527 | MergeOperator: mo, |
| 528 | OnEvent: func(event Event) { |
| 529 | mu.Lock() |
| 530 | counts[event.Kind]++ |
| 531 | durations[event.Kind] += event.Duration |
| 532 | eventWaiter := eventWaiters[event.Kind] |
| 533 | mu.Unlock() |
| 534 | if eventWaiter != nil { |
| 535 | eventWaiter <- true |
| 536 | } |
| 537 | }, |
| 538 | } |
| 539 | |
| 540 | store, err := OpenStore(tmpDir, StoreOptions{ |
| 541 | CollectionOptions: co, |
| 542 | }) |
| 543 | if err != nil || store == nil { |
| 544 | t.Errorf("expected open empty store to work") |
| 545 | } |
| 546 | |
| 547 | ssInit, err := store.Snapshot() |
| 548 | if err != nil || ssInit == nil { |
| 549 | t.Errorf("expected ssInit") |
| 550 | } |
| 551 | |
| 552 | co.LowerLevelInit = ssInit |
| 553 | co.LowerLevelUpdate = func(higher Snapshot) (Snapshot, error) { |
| 554 | return store.Persist(higher, spo) |
| 555 | } |
| 556 | |
| 557 | m, err := NewCollection(co) |
| 558 | if err != nil || m == nil { |
| 559 | t.Errorf("expected moss") |
| 560 | } |
| 561 | |
| 562 | m.Start() |
| 563 | |
| 564 | persistWaiterCh := make(chan bool, 100) |
| 565 | |
| 566 | mu.Lock() |
| 567 | eventWaiters[EventKindPersisterProgress] = persistWaiterCh |
| 568 | mu.Unlock() |
| 569 | |
| 570 | testOps(t, m) |
| 571 | |
| 572 | err = m.(*collection).NotifyMerger("mergeAll", true) |
no test coverage detected
searching dependent graphs…