Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing issue with expressions pending #125520

Merged
merged 1 commit into from
Feb 14, 2022
Merged
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
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