|
1 | 1 | /* global describe, it */ |
2 | 2 | 'use strict' |
3 | | - |
4 | 3 | const request = require('supertest') |
5 | 4 | const bodyParser = require('body-parser') |
| 5 | +const { promisify } = require('util') |
6 | 6 | const { expect } = require('chai') |
| 7 | + |
| 8 | +const sleep = promisify(setTimeout) |
| 9 | + |
7 | 10 | let gateway, service, close, proxy, gHttpServer |
8 | 11 |
|
9 | 12 | describe('undici', () => { |
10 | 13 | it('init', async () => { |
11 | 14 | const fastProxy = require('../index')({ |
12 | 15 | base: 'http://127.0.0.1:3000', |
13 | 16 | undici: { |
14 | | - pipelining: 10 |
| 17 | + pipelining: 10, |
| 18 | + requestTimeout: 100 |
15 | 19 | } |
16 | 20 | }) |
17 | 21 | close = fastProxy.close |
@@ -45,6 +49,10 @@ describe('undici', () => { |
45 | 49 | res.setHeader('x-agent', 'fast-proxy') |
46 | 50 | res.send() |
47 | 51 | }) |
| 52 | + service.get('/service/timeout', async (req, res) => { |
| 53 | + await sleep(200) |
| 54 | + res.send() |
| 55 | + }) |
48 | 56 |
|
49 | 57 | service.start(3000).then(() => done()) |
50 | 58 | }) |
@@ -75,6 +83,12 @@ describe('undici', () => { |
75 | 83 | }) |
76 | 84 | }) |
77 | 85 |
|
| 86 | + it('should 200 on GET /service/timeout', async () => { |
| 87 | + await request(gHttpServer) |
| 88 | + .get('/service/timeout') |
| 89 | + .expect(504) |
| 90 | + }) |
| 91 | + |
78 | 92 | it('close all', async () => { |
79 | 93 | close() |
80 | 94 | await gateway.close() |
|
0 commit comments