(t *testing.T)
| 1260 | } |
| 1261 | |
| 1262 | func TestReplace(t *testing.T) { |
| 1263 | dms := NewDiskMetricStore("", 100*time.Millisecond, nil, logger) |
| 1264 | |
| 1265 | // First do an invalid push to set pushFailedTimestamp and to later |
| 1266 | // verify that it is retained and not replaced. |
| 1267 | ts1 := time.Now() |
| 1268 | grouping1 := map[string]string{ |
| 1269 | "job": "job1", |
| 1270 | } |
| 1271 | errCh := make(chan error, 1) |
| 1272 | dms.SubmitWriteRequest(WriteRequest{ |
| 1273 | Labels: grouping1, |
| 1274 | Timestamp: ts1, |
| 1275 | MetricFamilies: testutil.MetricFamiliesMap(mf1ts), |
| 1276 | Done: errCh, |
| 1277 | }) |
| 1278 | var err error |
| 1279 | for err = range errCh { |
| 1280 | if err != errTimestamp { |
| 1281 | t.Errorf("Expected error %q, got %q.", errTimestamp, err) |
| 1282 | } |
| 1283 | } |
| 1284 | if err == nil { |
| 1285 | t.Error("Expected error on pushing metric with timestamp.") |
| 1286 | } |
| 1287 | pushTimestamp := newPushTimestampGauge(grouping1, time.Time{}) |
| 1288 | pushFailedTimestamp := newPushFailedTimestampGauge(grouping1, ts1) |
| 1289 | if err := checkMetricFamilies( |
| 1290 | dms, |
| 1291 | pushTimestamp, pushFailedTimestamp, |
| 1292 | ); err != nil { |
| 1293 | t.Error(err) |
| 1294 | } |
| 1295 | |
| 1296 | // Now a valid update in replace mode. It doesn't replace anything, but |
| 1297 | // it already tests that the push-failed timestamp is retained. |
| 1298 | ts2 := ts1.Add(time.Second) |
| 1299 | errCh = make(chan error, 1) |
| 1300 | dms.SubmitWriteRequest(WriteRequest{ |
| 1301 | Labels: grouping1, |
| 1302 | Timestamp: ts2, |
| 1303 | MetricFamilies: testutil.MetricFamiliesMap(mf1a), |
| 1304 | Done: errCh, |
| 1305 | Replace: true, |
| 1306 | }) |
| 1307 | for err := range errCh { |
| 1308 | t.Fatal("Unexpected error:", err) |
| 1309 | } |
| 1310 | pushTimestamp = newPushTimestampGauge(grouping1, ts2) |
| 1311 | if err := checkMetricFamilies( |
| 1312 | dms, mf1a, |
| 1313 | pushTimestamp, pushFailedTimestamp, |
| 1314 | ); err != nil { |
| 1315 | t.Error(err) |
| 1316 | } |
| 1317 | |
| 1318 | // Now push something else in replace mode that should replace mf1. |
| 1319 | ts3 := ts2.Add(time.Second) |
nothing calls this directly
no test coverage detected
searching dependent graphs…