(t *testing.T)
| 685 | } |
| 686 | |
| 687 | func TestResyncUsingDCPStream(t *testing.T) { |
| 688 | base.TestRequiresDCPResync(t) |
| 689 | base.LongRunningTest(t) |
| 690 | |
| 691 | testCases := []struct { |
| 692 | docsCreated int |
| 693 | }{ |
| 694 | { |
| 695 | docsCreated: 0, |
| 696 | }, |
| 697 | { |
| 698 | docsCreated: 1000, |
| 699 | }, |
| 700 | } |
| 701 | |
| 702 | syncFn := ` |
| 703 | function(doc) { |
| 704 | channel("x") |
| 705 | }` |
| 706 | |
| 707 | for _, testCase := range testCases { |
| 708 | t.Run(fmt.Sprintf("Docs %d", testCase.docsCreated), func(t *testing.T) { |
| 709 | rt := rest.NewRestTester(t, |
| 710 | &rest.RestTesterConfig{ |
| 711 | SyncFn: syncFn, |
| 712 | }, |
| 713 | ) |
| 714 | defer rt.Close() |
| 715 | |
| 716 | for i := 0; i < testCase.docsCreated; i++ { |
| 717 | rt.CreateTestDoc(fmt.Sprintf("doc%d", i)) |
| 718 | } |
| 719 | |
| 720 | err := rt.WaitForCondition(func() bool { |
| 721 | return int(rt.GetDatabase().DbStats.Database().SyncFunctionCount.Value()) == testCase.docsCreated |
| 722 | }) |
| 723 | assert.NoError(t, err) |
| 724 | rt.GetDatabase().DbStats.Database().SyncFunctionCount.Set(0) |
| 725 | |
| 726 | response := rt.SendAdminRequest("POST", "/db/_resync?action=start", "") |
| 727 | rest.RequireStatus(t, response, http.StatusServiceUnavailable) |
| 728 | |
| 729 | rt.TakeDbOffline() |
| 730 | |
| 731 | response = rt.SendAdminRequest("POST", "/db/_resync?action=start", "") |
| 732 | rest.RequireStatus(t, response, http.StatusOK) |
| 733 | |
| 734 | resyncManagerStatus := rt.WaitForResyncDCPStatus(db.BackgroundProcessStateCompleted) |
| 735 | |
| 736 | assert.Equal(t, testCase.docsCreated, int(rt.GetDatabase().DbStats.Database().SyncFunctionCount.Value())) |
| 737 | if !base.UnitTestUrlIsWalrus() && !base.TestsDisableGSI() { |
| 738 | // It is possible for Couchbase Server GSI runs which use DCP purge to two DCP events from a previous |
| 739 | // test. |
| 740 | // 1. doc1 mutation |
| 741 | // 2. doc1 deletion |
| 742 | // |
| 743 | // In a test, these will not be resynced but docsProcessed is incremented. Relax |
| 744 | // the assertion to greater than the number of documents. |
nothing calls this directly
no test coverage detected