Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/scenes/src/behaviors/SceneQueryController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,41 @@ describe('SceneQueryController', () => {
expect((window as any).__grafanaRunningQueryCount).toBe(0);
});

it('should NOT mark query as complete on PartialResult, only on Done', async () => {
const { query, streamFuncs } = registerQuery(scene);
let next = jest.fn();

query.subscribe({ next });

expect((window as any).__grafanaRunningQueryCount).toBe(1);
expect(controller.state.isRunning).toBe(true);

// PartialResult emissions should not complete the query
streamFuncs.next({ state: LoadingState.PartialResult });
expect((window as any).__grafanaRunningQueryCount).toBe(1);
expect(controller.state.isRunning).toBe(true);

streamFuncs.next({ state: LoadingState.PartialResult });
expect((window as any).__grafanaRunningQueryCount).toBe(1);
expect(controller.state.isRunning).toBe(true);

// Final Done should complete it
streamFuncs.next({ state: LoadingState.Done });
expect((window as any).__grafanaRunningQueryCount).toBe(0);
expect(controller.state.isRunning).toBe(false);
});

it('should still mark query as complete on Streaming state', async () => {
const { query, streamFuncs } = registerQuery(scene);

query.subscribe(() => {});

expect(controller.state.isRunning).toBe(true);

streamFuncs.next({ state: LoadingState.Streaming });
expect(controller.state.isRunning).toBe(false);
});

it('Last unsubscribe should set running to false', async () => {
const { query: query1 } = registerQuery(scene);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function registerQueryWithController<T extends QueryResultWithState>(

const sub = queryStream.subscribe({
next: (v) => {
if (!markedAsCompleted && v.state !== LoadingState.Loading) {
if (!markedAsCompleted && v.state !== LoadingState.Loading && v.state !== LoadingState.PartialResult) {
markedAsCompleted = true;
queryControler.queryCompleted(entry);
endQueryCallback?.(performance.now()); // Success case - no error
Expand Down
Loading