Skip to content

Commit

Permalink
feat(api7): support route-level timeout (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored Oct 17, 2024
1 parent 15d7bf6 commit 108a303
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
75 changes: 75 additions & 0 deletions libs/backend-api7/e2e/resources/route.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as ADCSDK from '@api7/adc-sdk';

import { BackendAPI7 } from '../../src';
import {
createEvent,
deleteEvent,
dumpConfiguration,
syncEvents,
} from '../support/utils';

describe('Route E2E', () => {
let backend: BackendAPI7;

beforeAll(() => {
backend = new BackendAPI7({
server: process.env.SERVER,
token: process.env.TOKEN,
tlsSkipVerify: true,
gatewayGroup: 'default',
});
});

describe('Timeout', () => {
const serviceName = 'test';
const service = {
name: serviceName,
upstream: {
scheme: 'https',
nodes: [
{
host: 'httpbin.org',
port: 443,
weight: 100,
},
],
},
path_prefix: '/test',
strip_path_prefix: true,
} as ADCSDK.Service;
const route1Name = 'route1';
const route1 = {
name: route1Name,
uris: ['/route1'],
timeout: {
connect: 111,
send: 222,
read: 333,
},
} as ADCSDK.Route;

it('Create resources', async () =>
syncEvents(backend, [
createEvent(ADCSDK.ResourceType.SERVICE, serviceName, service),
createEvent(ADCSDK.ResourceType.ROUTE, route1Name, route1, serviceName),
]));

it('Dump', async () => {
const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration;
expect(result.services).toHaveLength(1);
expect(result.services[0]).toMatchObject(service);
expect(result.services[0].routes).toHaveLength(1);
expect(result.services[0].routes[0]).toMatchObject(route1);
});

it('Delete', async () =>
syncEvents(backend, [
deleteEvent(ADCSDK.ResourceType.SERVICE, serviceName),
]));

it('Dump again (service should not exist)', async () => {
const result = (await dumpConfiguration(backend)) as ADCSDK.Configuration;
expect(result.services).toHaveLength(0);
});
});
});
2 changes: 2 additions & 0 deletions libs/backend-api7/src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ToADC {
enable_websocket: route.enable_websocket,
plugins: route.plugins,
priority: route.priority,
timeout: route.timeout,
metadata: { id: route.route_id },
});
}
Expand Down Expand Up @@ -146,6 +147,7 @@ export class FromADC {
service_id: serviceId,
paths: route.uris,
priority: route.priority,
timeout: route.timeout,
});
}

Expand Down
1 change: 1 addition & 0 deletions libs/backend-api7/src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Route {
// misc
enable_websocket?: boolean;
priority?: number;
timeout?: UpstreamTimeout;
}
export interface StreamRoute {
id?: string;
Expand Down

0 comments on commit 108a303

Please sign in to comment.