(t *testing.T)
| 525 | } |
| 526 | |
| 527 | func TestRuler_TestShutdown(t *testing.T) { |
| 528 | tests := []struct { |
| 529 | name string |
| 530 | shutdownFn func(*blockingQuerier, *Ruler) |
| 531 | }{ |
| 532 | { |
| 533 | name: "successful query after shutdown", |
| 534 | shutdownFn: func(querier *blockingQuerier, ruler *Ruler) { |
| 535 | // Wait query to start |
| 536 | <-querier.queryStarted |
| 537 | |
| 538 | // The following cancel the context of the ruler service. |
| 539 | ruler.StopAsync() |
| 540 | |
| 541 | // Simulate the completion of the query |
| 542 | close(querier.queryBlocker) |
| 543 | |
| 544 | // Wait query to finish |
| 545 | <-querier.queryFinished |
| 546 | |
| 547 | require.GreaterOrEqual(t, querier.successfulQueries.Load(), int64(1), "query failed to complete successfully failed to complete") |
| 548 | }, |
| 549 | }, |
| 550 | { |
| 551 | name: "query timeout while shutdown", |
| 552 | shutdownFn: func(querier *blockingQuerier, ruler *Ruler) { |
| 553 | // Wait query to start |
| 554 | <-querier.queryStarted |
| 555 | |
| 556 | // The following cancel the context of the ruler service. |
| 557 | ruler.StopAsync() |
| 558 | |
| 559 | // Wait query to finish |
| 560 | <-querier.queryFinished |
| 561 | |
| 562 | require.Equal(t, querier.successfulQueries.Load(), int64(0), "query should not be succesfull") |
| 563 | }, |
| 564 | }, |
| 565 | } |
| 566 | |
| 567 | for _, test := range tests { |
| 568 | t.Run(test.name, func(t *testing.T) { |
| 569 | store := newMockRuleStore(mockRules, nil) |
| 570 | cfg := defaultRulerConfig(t) |
| 571 | mockQuerier := &blockingQuerier{ |
| 572 | queryBlocker: make(chan struct{}), |
| 573 | queryStarted: make(chan struct{}), |
| 574 | queryFinished: make(chan struct{}), |
| 575 | successfulQueries: atomic.NewInt64(0), |
| 576 | } |
| 577 | sleepQueriable := fixedQueryable(mockQuerier) |
| 578 | |
| 579 | d := &querier.MockDistributor{} |
| 580 | |
| 581 | d.On("QueryStream", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( |
| 582 | &client.QueryStreamResponse{ |
| 583 | Chunkseries: []client.TimeSeriesChunk{}, |
| 584 | }, nil) |
nothing calls this directly
no test coverage detected