2

I've been writing the server side of a fitness webkit application. HTTP calls are sent to the server to start a time based "workout" in the application. I've been using jasmine-node to test and it's been working so far. The only time it doesn't work is if I'm trying to use sinon fake timers.

The problem I have is that the test doesn't make it past the it statement in the code below. It works if I remove the clock.tick function call. Why would it not move on from the it statement if the clock has been ticked by 120000 ms? Without the commented out clock.restore() in the .end of the get request, the request never finishes. I'm having trouble figuring out where exactly the problem comes from (jasmine-node vs express vs supertest). After that, it's still a matter of fixing the problem.

Behavior so far

  • With the clock initialized at all, the test won't finish.
  • With the clock initialized and the commented out clock.restore() uncommented, it works if the clock hasn't been ticked at all.
  • With the clock initialized and clock.restore() commented out, it hangs, but 'donee' is logged in the console.

Here is some example code:

var app = require('../../js/server');
var sinon = require('sinon');
var request = require('supertest');
var clock;
request = request(url + version);

describe("Active Workout REST", function(){
    beforeEach(function(){
        clock = sinon.useFakeTimers(new Date().getTime());
        app.start();
        // runs(function(){
            var workoutSetup = { 
                workout: 'cardio',
                intensity: 1
                }
            //sending workoutSetup
            request
                .post('/workout/setup')
                .set('Accept', 'application/json')
                .send(workoutSetup)
                .end(function(err, res){
                    console.log("done");
                });
            //sending start request
            request
                .post('/workout')
                .send({ workout: 'start'})
                .set('Accept', 'text/plain')
                .end(function(err, res){
                    console.log("done");
                });
            //get out of the warmup period
            console.log(new Date().getTime());
            clock.tick(2 * defs.MINUTES_TO_SECONDS * defs.SECONDS_TO_MS);
        // });
            console.log(new Date().getTime());
    });

    afterEach(function(){
        console.log("am i here?");
        clock.restore();
        app.stop();
    });

    it("should return current parameters", function(done){
        runs(function(){
            request
                .get('/workout/parameters/current')
                .set('Accept', 'application/json')
                .expect({
                    incline: 0,
                    duration_sec: 60
                })
                .end(function(err, res){
                    expect(err).toBe(null);
                    console.log('donee');
                    // clock.restore();
                    done();
                });
        });
    });
});
  • Are you using sequelize? I've noticed that for me it was a problem with never-ending test because sequelize could not release connection from its pool, each connection is added to pool with some idle time. – mieszko4 Apr 21 '16 at 13:34

0 Answers0