How to use the @hapi/hoek.Bench 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 hapijs / catbox / lib / policy.js View on Github external
async _get(pending, key) {

        // Prepare report

        const report = {};

        // Lookup in cache

        const timer = new Hoek.Bench();

        let cached = null;
        if (this._cache) {
            try {
                cached = await this._cache.get({ segment: this._segment, id: pending.id });
            }
            catch (err) {
                report.error = err;
                ++this.stats.errors;
                this._error('persist', err);
            }
        }

        report.msec = timer.elapsed();

        if (cached) {
github hapijs / hapi / test / core.js View on Github external
it('immediately destroys idle keep-alive connections', async () => {

            const server = Hapi.server();
            server.route({ method: 'GET', path: '/', handler: () => null });

            await server.start();

            const socket = await internals.socket(server);
            socket.write('GET / HTTP/1.1\nHost: test\nConnection: Keep-Alive\n\n\n');
            await new Promise((resolve) => socket.on('data', resolve));

            const count = await internals.countConnections(server);
            expect(count).to.equal(1);

            const timer = new Hoek.Bench();
            await server.stop({ timeout: 20 });
            expect(timer.elapsed()).to.be.at.most(20);
        });
github hapijs / hapi / test / payload.js View on Github external
const options = {
                hostname: '127.0.0.1',
                port: server.info.port,
                path: '/',
                method: 'POST'
            };

            const req = Http.request(options);
            req.on('error', Hoek.ignore);
            req.write('{}\n');
            setTimeout(() => req.end(), 100);
            return new Promise((resolve) => req.once('response', resolve));
        };

        const timer = new Hoek.Bench();
        const res = await request();
        expect(res.statusCode).to.equal(408);
        expect(timer.elapsed()).to.be.at.least(50);

        await server.stop({ timeout: 1 });
    });
github hapijs / hapi / test / request.js View on Github external
this.push('Hello');

                    setTimeout(() => {

                        this.push(null);
                        ended = true;
                    }, 150);
                }
            };

            const handler = (request) => {

                return new TestStream();
            };

            const timer = new Hoek.Bench();

            const server = Hapi.server({ routes: { timeout: { server: 100 } } });
            server.route({ method: 'GET', path: '/', handler });
            await server.start();
            const { res } = await Wreck.get('http://localhost:' + server.info.port);
            expect(ended).to.be.true();
            expect(timer.elapsed()).to.be.at.least(150);
            expect(res.statusCode).to.equal(200);
            await server.stop({ timeout: 1 });
        });
github hapijs / heavy / lib / index.js View on Github external
exports = module.exports = internals.Heavy = function (options) {

    options = options || {};

    Joi.assert(options, internals.schema, 'Invalid load monitoring options');
    this.settings = Hoek.applyToDefaults(internals.defaults, options);
    Hoek.assert(this.settings.sampleInterval || (!this.settings.maxEventLoopDelay && !this.settings.maxHeapUsedBytes && !this.settings.maxRssBytes), 'Load sample interval must be set to enable load limits');

    this._eventLoopTimer = null;
    this._loadBench = new Hoek.Bench();
    this.load = {
        eventLoopDelay: 0,
        heapUsed: 0,
        rss: 0
    };
};