MCPcopy
hub / github.com/garethgeorge/backrest / tryExpectOperationsSynced

Function tryExpectOperationsSynced

internal/api/syncapi/syncapi_test.go:572–623  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, peer1 *peerUnderTest, peer2 *peerUnderTest, query oplog.Query, message string)

Source from the content-addressed store, hash-verified

570}
571
572func tryExpectOperationsSynced(t *testing.T, ctx context.Context, peer1 *peerUnderTest, peer2 *peerUnderTest, query oplog.Query, message string) {
573 err := testutil.Retry(t, ctx, func() error {
574 peer1Ops := getOperations(t, peer1.oplog, query)
575 peer2Ops := getOperations(t, peer2.oplog, query)
576 // clear fields that we expect will be re-mapped
577 for _, op := range peer1Ops {
578 op.Id = 0
579 op.FlowId = 0
580 op.OriginalId = 0
581 op.OriginalFlowId = 0
582 op.OriginalInstanceKeyid = ""
583 op.Modno = 0
584 }
585 for _, op := range peer2Ops {
586 op.Id = 0
587 op.FlowId = 0
588 op.OriginalId = 0
589 op.OriginalFlowId = 0
590 op.OriginalInstanceKeyid = ""
591 op.Modno = 0
592 }
593
594 sortFn := func(a, b *v1.Operation) int {
595 if a.DisplayMessage < b.DisplayMessage {
596 return -1
597 }
598 return 1
599 }
600
601 slices.SortFunc(peer1Ops, sortFn)
602 slices.SortFunc(peer2Ops, sortFn)
603
604 if len(peer1Ops) == 0 {
605 return errors.New("no operations found in peer1")
606 }
607 if len(peer2Ops) == 0 {
608 return errors.New("no operations found in peer2")
609 }
610 if diff := cmp.Diff(peer1Ops, peer2Ops, protocmp.Transform()); diff != "" {
611 return fmt.Errorf("%s: unexpected diff: %v", message, diff)
612 }
613
614 return nil
615 })
616 if err != nil {
617 ops1Json, _ := protojson.MarshalOptions{Indent: " "}.Marshal(&v1.OperationList{Operations: getOperations(t, peer1.oplog, query)})
618 ops2Json, _ := protojson.MarshalOptions{Indent: " "}.Marshal(&v1.OperationList{Operations: getOperations(t, peer2.oplog, query)})
619 t.Logf("peer1 operations: %v", string(ops1Json))
620 t.Logf("peer2 operations: %v", string(ops2Json))
621 t.Fatalf("timeout without syncing operations: %v", err)
622 }
623}
624
625func tryExpectConfigFromHost(t *testing.T, ctx context.Context, peer *peerUnderTest, hostPeer *v1.Multihost_Peer, wantCfg *v1sync.RemoteConfig) {
626 testutil.Try(t, ctx, func() error {

Callers 2

TestSimpleOperationSyncFunction · 0.85
TestSyncMutationsFunction · 0.85

Calls 3

RetryFunction · 0.92
getOperationsFunction · 0.70
TransformMethod · 0.65

Tested by

no test coverage detected