(t *testing.T)
| 752 | } |
| 753 | |
| 754 | func TestResyncUsingDCPStreamReset(t *testing.T) { |
| 755 | base.TestRequiresDCPResync(t) |
| 756 | base.LongRunningTest(t) |
| 757 | |
| 758 | syncFn := ` |
| 759 | function(doc) { |
| 760 | channel("x") |
| 761 | }` |
| 762 | |
| 763 | rt := rest.NewRestTester(t, |
| 764 | &rest.RestTesterConfig{ |
| 765 | SyncFn: syncFn, |
| 766 | }, |
| 767 | ) |
| 768 | defer rt.Close() |
| 769 | |
| 770 | const numDocs = 1000 |
| 771 | |
| 772 | // create some docs |
| 773 | for i := 0; i < numDocs; i++ { |
| 774 | rt.CreateTestDoc(fmt.Sprintf("doc%d", i)) |
| 775 | } |
| 776 | |
| 777 | rt.TakeDbOffline() |
| 778 | |
| 779 | // start a resync run |
| 780 | response := rt.SendAdminRequest("POST", "/db/_resync?action=start", "") |
| 781 | rest.RequireStatus(t, response, http.StatusOK) |
| 782 | |
| 783 | resyncManagerStatus := rt.WaitForResyncDCPStatus(db.BackgroundProcessStateRunning) |
| 784 | resyncID := resyncManagerStatus.ResyncID |
| 785 | |
| 786 | // stop resync before it completes, assert it has been aborted |
| 787 | response = rt.SendAdminRequest("POST", "/db/_resync?action=stop", "") |
| 788 | rest.RequireStatus(t, response, http.StatusOK) |
| 789 | |
| 790 | _ = rt.WaitForResyncDCPStatus(db.BackgroundProcessStateStopped) |
| 791 | |
| 792 | // reset the resync process through the endpoint |
| 793 | response = rt.SendAdminRequest("POST", "/db/_resync?reset=true", "") |
| 794 | rest.RequireStatus(t, response, http.StatusOK) |
| 795 | |
| 796 | // grab new resync status from rest run, assert the resync if is not the same as the first |
| 797 | // run and that the docs processed is equal to number of docs we have created |
| 798 | resyncManagerStatus = rt.WaitForResyncDCPStatus(db.BackgroundProcessStateRunning) |
| 799 | assert.NotEqual(t, resyncID, resyncManagerStatus.ResyncID) |
| 800 | |
| 801 | resyncManagerStatus = rt.WaitForResyncDCPStatus(db.BackgroundProcessStateCompleted) |
| 802 | if !base.UnitTestUrlIsWalrus() && !base.TestsDisableGSI() { |
| 803 | // It is possible for Couchbase Server GSI runs which use DCP purge to two DCP events from a previous |
| 804 | // test. |
| 805 | // 1. doc1 mutation |
| 806 | // 2. doc1 deletion |
| 807 | // |
| 808 | // In a test, these will not be resynced but docsProcessed is incremented. Relax |
| 809 | // the assertion to greater than the number of documents. |
| 810 | assert.GreaterOrEqual(t, int(resyncManagerStatus.DocsProcessed), numDocs) |
| 811 | } else { |
nothing calls this directly
no test coverage detected