How to use the @loopback/testlab.httpGetAsync function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / http-server / src / __tests__ / integration / http-server.integration.ts View on Github external
// Send a request with keep-alive
    const req = httpGetAsync(server.url, agent);
    // Wait until the request is accepted by the server
    await pEvent(server.server, 'request');
    // Stop the server
    const stop = server.stop();
    // Now notify the request to finish in next cycle with setImmediate
    setImmediate(() => {
      emitter.emit('finish');
    });
    // The in-flight task can finish before the grace period
    await req;
    // Wait until the server is stopped
    await stop;
    // No more new connections are accepted
    await expect(httpGetAsync(server.url)).to.be.rejectedWith(/ECONNREFUSED/);
  });
github strongloop / loopback-next / packages / http-server / src / __tests__ / integration / http-server.integration.ts View on Github external
it('stops server with grace period and inflight request', async () => {
    const serverOptions = givenHttpServerConfig() as HttpServerOptions;
    serverOptions.gracePeriodForClose = 1000;
    const {emitter, deferredRequestHandler} = createDeferredRequestHandler();
    server = new HttpServer(deferredRequestHandler, serverOptions);
    await server.start();
    const agent = new Agent({keepAlive: true});
    // Send a request with keep-alive
    const req = httpGetAsync(server.url, agent);
    // Wait until the request is accepted by the server
    await pEvent(server.server, 'request');
    // Stop the server
    const stop = server.stop();
    // Now notify the request to finish in next cycle with setImmediate
    setImmediate(() => {
      emitter.emit('finish');
    });
    // The in-flight task can finish before the grace period
    await req;
    // Wait until the server is stopped
    await stop;
    // No more new connections are accepted
    await expect(httpGetAsync(server.url)).to.be.rejectedWith(/ECONNREFUSED/);
  });
github strongloop / loopback-next / packages / http-server / src / __tests__ / integration / http-server.integration.ts View on Github external
it('stops server with shorter grace period and inflight request', async () => {
    const serverOptions = givenHttpServerConfig() as HttpServerOptions;
    serverOptions.gracePeriodForClose = 10;
    const {deferredRequestHandler} = createDeferredRequestHandler();
    server = new HttpServer(deferredRequestHandler, serverOptions);
    await server.start();
    const agent = new Agent({keepAlive: true});
    // Send a request with keep-alive
    const req = httpGetAsync(server.url, agent);
    // Wait until the request is accepted by the server
    await pEvent(server.server, 'request');
    // Stop the server
    await server.stop();
    // No more new connections are accepted
    await expect(httpGetAsync(server.url)).to.be.rejectedWith(/ECONNREFUSED/);
    // We never send `finish` to the pending request
    // The inflight request is aborted as it takes longer than the grace period
    await expect(req).to.be.rejectedWith(/socket hang up/);
  });
github strongloop / loopback-next / packages / http-server / src / __tests__ / integration / http-server.integration.ts View on Github external
skipOnTravis(it, 'supports HTTP over IPv6', async () => {
    server = new HttpServer(dummyRequestHandler, {host: '::1'});
    await server.start();
    expect(getAddressFamily(server)).to.equal('IPv6');
    const response = await httpGetAsync(server.url);
    expect(response.statusCode).to.equal(200);
  });