Skip to content

Commit

Permalink
fixing issue with expressions pending (#125520)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Feb 14, 2022
1 parent 435b772 commit cc74733
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* Side Public License, v 1.
*/

import { Observable, Subscriber } from 'rxjs';
import { first } from 'rxjs/operators';
import { Execution } from './execution';
import { parseExpression } from '../ast';
import { createUnitTestExecutor } from '../test_helpers';
import { ExecutionContract } from './execution_contract';
import { ExpressionFunctionDefinition } from '../expression_functions';

const createExecution = (
expression: string = 'foo bar=123',
Expand Down Expand Up @@ -117,11 +119,40 @@ describe('ExecutionContract', () => {
const contract = new ExecutionContract(execution);

execution.start();
await execution.result.pipe(first()).toPromise();
execution.state.get().state = 'error';

expect(contract.isPending).toBe(false);
expect(execution.state.get().state).toBe('error');
});

test('is true when execution is in progress but got partial result, is false once we get final result', async () => {
let mySubscriber: Subscriber<number>;
const arg = new Observable((subscriber) => {
mySubscriber = subscriber;
subscriber.next(1);
});

const observable: ExpressionFunctionDefinition<'observable', unknown, {}, unknown> = {
name: 'observable',
args: {},
help: '',
fn: () => arg,
};
const executor = createUnitTestExecutor();
executor.registerFunction(observable);

const execution = executor.createExecution('observable');
execution.start(null);
await execution.result.pipe(first()).toPromise();

expect(execution.contract.isPending).toBe(true);
expect(execution.state.get().state).toBe('result');

mySubscriber!.next(2);
mySubscriber!.complete();

expect(execution.contract.isPending).toBe(false);
expect(execution.state.get().state).toBe('result');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { Adapters } from '../../../inspector/common/adapters';
*/
export class ExecutionContract<Input = unknown, Output = unknown, InspectorAdapters = unknown> {
public get isPending(): boolean {
const state = this.execution.state.get().state;
const finished = state === 'error' || state === 'result';
const { state, result } = this.execution.state.get();
const finished = state === 'error' || (state === 'result' && !result?.partial);
return !finished;
}

Expand Down

0 comments on commit cc74733

Please sign in to comment.