How to use the hoek.wait function in hoek

To help you get started, we’ve selected a few 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 outmoded / oz / test / client.js View on Github external
it('errors on reissue fail', async () => {

                const mock = new internals.Mock({ ttl: 10 });
                const uri = await mock.start();

                const connection = new Oz.client.Connection({ uri, credentials: internals.app });
                const { result: result1, code: code1, ticket: ticket1 } = await connection.app('/');
                expect(result1).to.equal('GET /');
                expect(code1).to.equal(200);
                expect(ticket1).to.equal(connection._appTicket);

                await Hoek.wait(11);        // Expire ticket

                let count = 0;
                const orig = Wreck.request;
                Wreck.request = function (...args) {

                    if (++count === 1) {
                        return orig.apply(Wreck, args);
                    }

                    Wreck.request = orig;
                    return Promise.reject(new Error('bad socket'));
                };

                await expect(connection.request('/resource', ticket1, { method: 'POST' })).to.reject();
                await mock.stop();
            });
github hapijs / hapi / test / core.js View on Github external
const handler = (request) => {

                const start = Date.now();
                while (Date.now() - start < 10) { }
                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(0);
            const res2 = await server.inject('/');
            expect(res2.statusCode).to.equal(503);

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

            await server.stop();
        });
    });
github hapijs / hapi / test / plugin.js View on Github external
});
            };

            test.attributes = {
                name: 'test'
            };

            const server = new Hapi.Server();
            await server.register(test);
            await server.initialize();

            await server.plugins.test.set('a', '1');
            const { value: value1 } = await server.plugins.test.get('a');
            expect(value1).to.equal('1');

            await Hoek.wait(11);
            const { value: value2 } = await server.plugins.test.get('a');
            expect(value2).to.equal(null);
        });
    });
github outmoded / oz / test / endpoints.js View on Github external
ttl: 5
                }
            };

            const ticket = await Oz.endpoints.app(req, null, options);

            req = {
                method: 'POST',
                url: '/oz/reissue',
                headers: {
                    host: 'example.com',
                    authorization: Oz.client.header('http://example.com/oz/reissue', 'POST', ticket).header
                }
            };

            await Hoek.wait(10);
            await expect(Oz.endpoints.reissue(req, {}, options)).to.not.reject();
        });
github btmorex / hapi-server-session / test / index.js View on Github external
runServer({cache: {expiresIn: 1}, expiresIn: 1000, key: 'test'}, async (server) => {
              let res = await server.testInjectWithValue();
              await hoek.wait(1);
              res = await server.testInject({cookie: extractCookie(res)});
              expect(res.request.session).to.deep.equal({});
              expect(res.statusCode).to.equal(200);
              expect(res.headers['set-cookie']).to.exist;
              expect(res.headers['set-cookie'][0]).to.equal(
                'id=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Lax; Path=/',
              );
            }));
        });
github outmoded / penseur / test / table.js View on Github external
const changes = [];
            const each = (err, item) => {

                if (!err) {
                    changes.push(item.type);
                }
                else {
                    changes.push(err.flags);
                }
            };

            await db.test.changes(1, { handler: each, initial: true });
            await db.test.insert([{ id: 1, a: 1 }]);

            await db._connection.close();
            await Hoek.wait(100);

            expect(changes).to.equal(['insert', { willReconnect: false, disconnected: true }]);
            expect(count).to.equal(1);
            await db.close();
        });
github hapijs / hapi / test / plugin.js View on Github external
server.route({
                method: 'GET',
                path: '/',
                handler: (request) => {

                    request.server.log('1');
                    throw new Error('2');
                }
            });

            await server.register(test);
            await server.start();

            const res = await server.inject('/');
            expect(res.statusCode).to.equal(500);
            await Hoek.wait(10);
            expect(updates).to.equal([['1'], 'request-error', 'response']);
            await server.stop();
        });
github outmoded / penseur / test / table.js View on Github external
expect(err).to.not.exist();
                changes2.push(item.after.a);
            };

            await db.test.insert([{ id: 1, a: 1 }]);

            await db.test.changes(1, each1);
            await db.test.changes(1, { handler: each2, squash: 1 });

            await db.test.update(1, { a: 2 });
            await db.test.update(1, { a: 3 });
            await db.test.update(1, { a: 4 });
            await db.test.update(1, { a: 5 });

            await Hoek.wait(1050);

            expect(changes1).to.equal([2, 3, 4, 5]);
            expect(changes2).to.equal([5]);

            await db.close();
        });
github hapijs / hapi / test / core.js View on Github external
let count = 0;
            server.route({
                method: 'GET',
                path: '/',
                handler: (request, responder) => {

                    ++count;
                    return responder.abandon;
                }
            });

            await server.start();
            const promise = Wreck.request('GET', `https://localhost:${server.info.port}/`, { rejectUnauthorized: false });

            await Hoek.wait(50);
            const count1 = await internals.countConnections(server);
            expect(count1).to.equal(1);
            expect(server._core.sockets.size).to.equal(1);
            expect(count).to.equal(1);

            promise.req.abort();
            await expect(promise).to.reject();

            const count2 = await internals.countConnections(server);
            expect(count2).to.equal(0);
            expect(server._core.sockets.size).to.equal(0);
            expect(count).to.equal(1);
            await server.stop();
        });
    });
github outmoded / penseur / lib / db.js View on Github external
const loop = async (err) => {

                first = false;
                await Hoek.wait(this._settings.reconnectTimeout && !first ? this._settings.reconnectTimeout : 0);

                this._settings.onError(err);
                try {
                    await this.connect();
                }
                catch (err) {
                    Bounce.rethrow(err, 'system');
                    await loop(err);
                }
            };