Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tape and server.inject problem #2723

Closed
ArtZanko opened this issue Aug 17, 2015 · 12 comments · Fixed by #2725
Closed

Tape and server.inject problem #2723

ArtZanko opened this issue Aug 17, 2015 · 12 comments · Fixed by #2725
Assignees
Labels
bug Bug or defect
Milestone

Comments

@ArtZanko
Copy link

Hello.We are using tape+gulp for testing our hapi server. At first I create a mock:

var server;
serverMock(function(obj) {
        server = obj;
        test.end();
    });

serverMock is a module

var _ = require('lodash');
var Hapi = require('hapi');
var config = require('../../config');
var cacheMock = require('./cache');

module.exports = function(done) {
    var server = new Hapi.Server();

    server.connection();

    server.route(require('../../server/routes'));

    var cache = server.cache({segment: 'first', expiresIn: config.cache.expiresIn});
    cache._cache.start(_.noop); 

    var methods = require('../../server/methods');

    server.method('first.cache', methods.cache, {bind: cache});
    server.method('first.get', methods.get, {bind: cache});

    cache.set(cacheMock.id, cacheMock);

    server.start(function() {
        return done(server);
    });
};

Then test is passing. And at the end:

server.stop();

I want to notice that all tape.end() functions is called but process still alive. I think its because server keep it alive. Maybe you can help me..

@hueniverse
Copy link
Contributor

You might want to give stop() a timeout option.

@hueniverse hueniverse added the support Questions, discussions, and general support label Aug 18, 2015
@hueniverse hueniverse self-assigned this Aug 18, 2015
@ArtZanko
Copy link
Author

Yes I did. Still doesn't work.

@hueniverse
Copy link
Contributor

No idea. You can try to run the code without the testing setup just to make sure as a standalone app it runs and exits correctly.

@ArtZanko
Copy link
Author

I tried to call server.stop in app without tesing setup and nothing happened(only stop callback was called but a process was alive).. Function server.stop should make a process exit, right?

@tthyer
Copy link

tthyer commented Aug 18, 2015

I had a similar problem using tape with hapi caching. I attempted using a timeout with stop, not starting the server and instead starting and stopping the cache itself, but still the test did not complete. I tracked the problem down to the timer set by Catbox-Memory and cleared it:
clearTimeout(server._caches._default.client.connection.cache['segmentName']['keyName'].timeoutId)
Then my test would complete.

Checking catbox-memory commits, it looks like there's a fix for this in master that hasn't been released yet.

@hueniverse
Copy link
Contributor

@cjihrig what's the status of the catbox-memory fix?

@hueniverse hueniverse reopened this Aug 18, 2015
@hueniverse hueniverse added bug Bug or defect and removed support Questions, discussions, and general support labels Aug 18, 2015
@cjihrig
Copy link
Contributor

cjihrig commented Aug 18, 2015

I'll do a release right now.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 18, 2015

@tthyer I just released v1.1.2 of catbox-memory. Care to give it a shot?

@tthyer
Copy link

tthyer commented Aug 18, 2015

Just confirmed that this works. Thanks!
@ArtZanko I used catbox-memory v1.1.2 as my cache engine, called server.stop and the tape test completed.

@hueniverse
Copy link
Contributor

@cjihrig can you PR to update hapi with the new version

@cjihrig
Copy link
Contributor

cjihrig commented Aug 18, 2015

Sure thing

@ArtZanko
Copy link
Author

Yes it works! Thank you very much!
One more question. When i call npm install hapi it install catbox-memory 1.1.1 as dependency I have to call npm update catbox-memory in hapi directory to update it. How to get catbox-memory latest version with just calling npm install in app directory?

I got it waiting for #2725

Thanks once again!

@hueniverse hueniverse added this to the 9.0.3 milestone Aug 19, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants