Skip to content

Commit

Permalink
propagate bazooka failure in auxo
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Oct 23, 2024
1 parent b9fcc40 commit 004ffc5
Show file tree
Hide file tree
Showing 3 changed files with 554 additions and 458 deletions.
75 changes: 72 additions & 3 deletions indexer/services/auxo/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
describe('index', () => {
it('true is true', () => {
expect(true).toEqual(true);
// handler.test.ts
import { handler } from '../src/index';
import * as helpers from '../src/helpers';
import { InvokeCommandOutput, LambdaClient } from '@aws-sdk/client-lambda';
import { APIGatewayEvent, Context } from 'aws-lambda';
import { AuxoEventJson } from 'src/types';

// Mock logger and startBugsnag from @dydxprotocol-indexer/base
jest.mock('@dydxprotocol-indexer/base', () => {
const originalModule = jest.requireActual('@dydxprotocol-indexer/base');
return {
...originalModule,
logger: {
info: jest.fn(),
error: jest.fn(),
crit: jest.fn(),
},
startBugsnag: jest.fn(),
};
});

describe('Auxo Handler', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should return 500 when Bazooka Lambda errors', async () => {
// Mock upgradeBazooka to do nothing
jest.spyOn(helpers, 'upgradeBazooka').mockResolvedValue(undefined);

// Mock LambdaClient.send to return response with FunctionError
jest.spyOn(LambdaClient.prototype, 'send').mockImplementation(() => {
return {
StatusCode: 500,
FunctionError: 'Some bazooka error',
$metadata: {
httpStatusCode: 200, // api returns 200 even if lambda runtime error
requestId: 'mock-request-id-invoke',
extendedRequestId: 'mock-extended-request-id-invoke',
cfId: 'mock-cf-id-invoke',
attempts: 1,
totalRetryDelay: 0,
},
} as InvokeCommandOutput;
});

const mockEvent: APIGatewayEvent & AuxoEventJson = {
// APIGatewayEvent properties
body: null,
headers: {},
multiValueHeaders: {},
httpMethod: 'POST',
isBase64Encoded: false,
path: '/deploy',
pathParameters: null,
queryStringParameters: null,
multiValueQueryStringParameters: null,
stageVariables: null,
resource: '',
requestContext: {} as any,
// AuxoEventJson properties
upgrade_tag: 'some_tag',
prefix: 'some_prefix',
region: 'us-east-1',
regionAbbrev: 'us-east-1',
addNewKafkaTopics: false,
onlyRunDbMigrationAndCreateKafkaTopics: false,
};

const mockContext: Context = {} as any;

await expect(handler(mockEvent, mockContext)).rejects.toThrow('bazooka failure: Some bazooka error');
});
});
Loading

0 comments on commit 004ffc5

Please sign in to comment.