mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
fixing issue with expressions pending (#125520)
This commit is contained in:
parent
435b772786
commit
cc74733a8b
2 changed files with 34 additions and 3 deletions
|
@ -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',
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue