(t *testing.T)
| 3133 | } |
| 3134 | |
| 3135 | func TestTombstoneCompactionAPI(t *testing.T) { |
| 3136 | rt := NewRestTester(t, nil) |
| 3137 | defer rt.Close() |
| 3138 | |
| 3139 | // force compaction |
| 3140 | rt.GetDatabase().Options.TestPurgeIntervalOverride = base.Ptr(time.Duration(0)) |
| 3141 | |
| 3142 | for i := 0; i < 100; i++ { |
| 3143 | docID := fmt.Sprintf("doc%d", i) |
| 3144 | version := rt.PutDoc(docID, "{}") |
| 3145 | rt.DeleteDoc(docID, version) |
| 3146 | } |
| 3147 | |
| 3148 | resp := rt.SendAdminRequest("GET", "/{{.db}}/_compact", "") |
| 3149 | RequireStatus(t, resp, http.StatusOK) |
| 3150 | |
| 3151 | var tombstoneCompactionStatus db.TombstoneManagerResponse |
| 3152 | err := base.JSONUnmarshal(resp.BodyBytes(), &tombstoneCompactionStatus) |
| 3153 | assert.NoError(t, err) |
| 3154 | |
| 3155 | assert.Equal(t, db.BackgroundProcessStateCompleted, tombstoneCompactionStatus.State) |
| 3156 | assert.Empty(t, tombstoneCompactionStatus.LastErrorMessage) |
| 3157 | assert.Equal(t, 0, int(tombstoneCompactionStatus.DocsPurged)) |
| 3158 | firstStartTimeStat := rt.GetDatabase().DbStats.Database().CompactionTombstoneStartTime.Value() |
| 3159 | assert.NotEqual(t, 0, firstStartTimeStat) |
| 3160 | |
| 3161 | resp = rt.SendAdminRequest("POST", "/{{.db}}/_compact", "") |
| 3162 | RequireStatus(t, resp, http.StatusOK) |
| 3163 | |
| 3164 | err = rt.WaitForCondition(func() bool { |
| 3165 | resp = rt.SendAdminRequest("GET", "/{{.db}}/_compact", "") |
| 3166 | RequireStatus(t, resp, http.StatusOK) |
| 3167 | |
| 3168 | err = base.JSONUnmarshal(resp.BodyBytes(), &tombstoneCompactionStatus) |
| 3169 | assert.NoError(t, err) |
| 3170 | |
| 3171 | return tombstoneCompactionStatus.State == db.BackgroundProcessStateCompleted |
| 3172 | }) |
| 3173 | assert.NoError(t, err) |
| 3174 | assert.True(t, rt.GetDatabase().DbStats.Database().CompactionTombstoneStartTime.Value() > firstStartTimeStat) |
| 3175 | |
| 3176 | resp = rt.SendAdminRequest("GET", "/{{.db}}/_compact", "") |
| 3177 | RequireStatus(t, resp, http.StatusOK) |
| 3178 | err = base.JSONUnmarshal(resp.BodyBytes(), &tombstoneCompactionStatus) |
| 3179 | assert.NoError(t, err) |
| 3180 | |
| 3181 | assert.Equal(t, db.BackgroundProcessStateCompleted, tombstoneCompactionStatus.State) |
| 3182 | assert.Empty(t, tombstoneCompactionStatus.LastErrorMessage) |
| 3183 | |
| 3184 | if base.TestUseXattrs() { |
| 3185 | assert.Equal(t, 100, int(tombstoneCompactionStatus.DocsPurged)) |
| 3186 | } else { |
| 3187 | assert.Equal(t, 0, int(tombstoneCompactionStatus.DocsPurged)) |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | // TestPing ensures that /_ping is accessible on all APIs for GET and HEAD without authentication. |
| 3192 | func TestPing(t *testing.T) { |
nothing calls this directly
no test coverage detected