How to use the @hapi/hoek.wait function in @hapi/hoek

To help you get started, we’ve selected a few @hapi/hoek 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 futurestudio / hapi-pulse / test / server-stop-with-signals.js View on Github external
const server = new Hapi.Server()
    await server.register({
      plugin: require('../lib'),
      options: {
        signals: 'HAPIPULSE'
      }
    })

    await server.start()
    // a stopped hapi server has a "started" timestamp of 0
    expect(server.info.started).to.not.equal(0)

    process.emit('HAPIPULSE')

    // wait for the server to stop
    await Hoek.wait(100)

    Sinon.assert.called(process.exit)

    // a stopped hapi server has a "started" timestamp of 0
    expect(server.info.started).to.equal(0)
  })
})
github hapijs / nes / test / listener.js View on Github external
}
            };

            let d = 0;
            client.onDisconnect = (willReconnect, log) => ++d;

            await client.connect();
            expect(client._heartbeatTimeout).to.equal(380);

            await client.request('/');
            await Hoek.wait(520);

            expect(d).to.equal(0);

            client._onMessage = Hoek.ignore;            // Stop processing messages
            await Hoek.wait(480);

            expect(d).to.equal(1);

            client.disconnect();
            await server.stop();
        });
    });
github hapijs / catbox / test / policy.js View on Github external
const orig = client.connection.get;
                client.connection.get = async function (key) {      // Delayed get

                    await Hoek.wait(100);
                    return orig.call(client.connection, key);
                };

                const policy = new Catbox.Policy(rule, client, 'test-segment');

                await client.start();

                const { value: value1, report: report1 } = await policy.get('test');        // Cache lookup takes 100 + generate 50
                expect(value1.gen).to.equal(1);                                             // Fresh
                expect(report1.error).to.not.exist();

                await Hoek.wait(210);                                                       // Wait for stale

                const { value: value2, report: report2 } = await policy.get('test');        // Cache lookup takes 100, generate comes back after 50
                expect(value2.gen).to.equal(2);                                             // Fresh
                expect(report2.error).to.not.exist();

                const { value: value3, report: report3 } = await policy.get('test');        // Cache lookup takes 100
                expect(value3.gen).to.equal(2);                                             // Cached (100 left to stale)
                expect(report3.error).to.not.exist();

                client.connection.get = orig;
            });
github futurestudio / hapi-pulse / test / server-stop-calling-methods.js View on Github external
const server = new Hapi.Server()
    await server.register({
      plugin: require('../lib'),
      options: {
        logger: { error: () => {} },
        signals: 'ERRORPULSE',
        postServerStop: stub
      }
    })

    await server.start()

    process.emit('ERRORPULSE')

    // wait for the server to stop
    await Hoek.wait(100)
    expect(process.listenerCount('ERRORPULSE')).to.equal(0)

    Sinon.assert.called(process.exit)
    Sinon.assert.called(stub)

    // a stopped hapi server has a "started" timestamp of 0
    expect(server.info.started).to.equal(0)
  })
github futurestudio / hapi-pulse / test / server-stop-on-SIGTERM.js View on Github external
it('stops the server on SIGTERM', async () => {
    await server.start()
    // a stopped hapi server has a "started" timestamp of 0
    expect(server.info.started).to.not.equal(0)

    process.emit('SIGTERM')

    // wait for the server to stop
    await Hoek.wait(100)
    Sinon.assert.called(process.exit)

    // a stopped hapi server has a "started" timestamp of 0
    expect(server.info.started).to.equal(0)
  })
github hapijs / nes / test / listener.js View on Github external
handler: async () => {

                    await Hoek.wait(440);
                    return 'hello';
                }
            });
github hapijs / hapi / test / methods.js View on Github external
const method = async function (id) {

            await Hoek.wait(50);
            return { id, gen: ++gen };
        };
github hapijs / hapi / test / core.js View on Github external
let buffer;
            const handler = (request) => {

                buffer = buffer || Buffer.alloc(2048);
                return 'ok';
            };

            const log = server.events.once('log');

            server.route({ method: 'GET', path: '/', handler });
            await server.start();

            const res1 = await server.inject('/');
            expect(res1.statusCode).to.equal(200);

            await Hoek.wait(10);
            const res2 = await server.inject('/');
            expect(res2.statusCode).to.equal(503);

            const [event, tags] = await log;
            expect(event.channel).to.equal('internal');
            expect(event.data.rss > 10000).to.equal(true);
            expect(tags.load).to.be.true();

            await server.stop();
        });
    });
github hapijs / podium / test / index.js View on Github external
const aHandler = async (data) => {

                await Hoek.wait(50);
                updates.push({ a: data, id: 1 });
            };
github hapijs / heavy / test / index.js View on Github external
it('fails check due to high rss load', async () => {

        const heavy = new Heavy({ sampleInterval: 5, maxRssBytes: 1 });

        heavy.start();
        expect(() => heavy.check()).to.not.throw();

        await Hoek.wait(10);

        expect(() => heavy.check()).to.throw('Server under heavy load (rss)');
        expect(heavy.load.rss).to.be.above(10000);
        heavy.stop();
    });