Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Jan 18, 2022
1 parent 72c3d3e commit 5dfe01c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { actionsMock, actionsClientMock } from '../mocks';
import { pick } from 'lodash';

const actionExecutor = new ActionExecutor({ isESOCanEncrypt: true });
getActionsClientWithRequest.mockResolvedValue(actionsClient);
const services = actionsMock.createServices();

const actionsClient = actionsClientMock.create();
Expand Down Expand Up @@ -51,6 +50,7 @@ actionExecutor.initialize({
beforeEach(() => {
jest.resetAllMocks();
spacesMock.getSpaceId.mockReturnValue('some-namespace');
getActionsClientWithRequest.mockResolvedValue(actionsClient);
});

test('successfully executes', async () => {
Expand Down Expand Up @@ -115,6 +115,7 @@ test('successfully executes', async () => {
Object {
"event": Object {
"action": "execute-start",
"kind": "action",
},
"kibana": Object {
"saved_objects": Array [
Expand All @@ -134,6 +135,7 @@ test('successfully executes', async () => {
Object {
"event": Object {
"action": "execute",
"kind": "action",
"outcome": "success",
},
"kibana": Object {
Expand Down
41 changes: 18 additions & 23 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class ActionExecutor {
private isInitialized = false;
private actionExecutorContext?: ActionExecutorContext;
private readonly isESOCanEncrypt: boolean;
private actionInfo: ActionInfo | undefined;

constructor({ isESOCanEncrypt }: { isESOCanEncrypt: boolean }) {
this.isESOCanEncrypt = isESOCanEncrypt;
Expand Down Expand Up @@ -126,17 +125,15 @@ export class ActionExecutor {
const spaceId = spaces && spaces.getSpaceId(request);
const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {};

if (!this.actionInfo || this.actionInfo.actionId !== actionId) {
this.actionInfo = await getActionInfoInternal(
await getActionsClientWithRequest(request, source),
encryptedSavedObjectsClient,
preconfiguredActions,
actionId,
namespace.namespace
);
}
const actionInfo = await getActionInfoInternal(
await getActionsClientWithRequest(request, source),
encryptedSavedObjectsClient,
preconfiguredActions,
actionId,
namespace.namespace
);

const { actionTypeId, name, config, secrets } = this.actionInfo;
const { actionTypeId, name, config, secrets } = actionInfo;

if (span) {
span.name = `execute_action ${actionTypeId}`;
Expand Down Expand Up @@ -299,15 +296,13 @@ export class ActionExecutor {

const spaceId = spaces && spaces.getSpaceId(request);
const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {};
if (!this.actionInfo || this.actionInfo.actionId !== actionId) {
this.actionInfo = await getActionInfoInternal(
await getActionsClientWithRequest(request, source),
encryptedSavedObjectsClient,
preconfiguredActions,
actionId,
namespace.namespace
);
}
const actionInfo = await getActionInfoInternal(
await getActionsClientWithRequest(request, source),
encryptedSavedObjectsClient,
preconfiguredActions,
actionId,
namespace.namespace
);
const task = taskInfo
? {
task: {
Expand All @@ -320,16 +315,16 @@ export class ActionExecutor {
const event = createActionEventLogRecordObject({
actionId,
action: EVENT_LOG_ACTIONS.executeTimeout,
message: `action: ${this.actionInfo.actionTypeId}:${actionId}: '${
this.actionInfo.name ?? ''
message: `action: ${actionInfo.actionTypeId}:${actionId}: '${
actionInfo.name ?? ''
}' execution cancelled due to timeout - exceeded default timeout of "5m"`,
...namespace,
...task,
savedObjects: [
{
type: 'action',
id: actionId,
typeId: this.actionInfo.actionTypeId,
typeId: actionInfo.actionTypeId,
relation: SAVED_OBJECT_REL_PRIMARY,
},
],
Expand Down

0 comments on commit 5dfe01c

Please sign in to comment.