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

tests fail intermittently with 400 #57

Closed
silesky opened this issue Sep 25, 2019 · 3 comments
Closed

tests fail intermittently with 400 #57

silesky opened this issue Sep 25, 2019 · 3 comments

Comments

@silesky
Copy link

silesky commented Sep 25, 2019

When I'm running tests where I'm spinning up new instances of express servers between suites, I'm getting intermittent 400 errors for the tests that deal with a particular POST endpoint (requestBody validation). The failure happens about once every couple of tries.

When I mock the validator or comment it out, all the tests pass consistently.

I'm not absolutely sure, but my hunch is that the test is running while the app is still in the "installation" phase. Is there a possibility of adding a callback or letting install() return a promise?

for reference, the tests that are failing are these:

    it('should create todo', async done => {
      const insertedTodo = todoCollection[0];
      await TodoModel.create(insertedTodo);
      request(expressMongoServer.app)
        .post('/v1/todo')
        .send(insertedTodo)
        .expect('Content-type', /json/)
        .end((err, res) => {
          expect(res.status).toEqual(201);
          const todoRes = res.body;
          expect(todoRes._id).toBeTruthy();
          expect(todoRes).toEqual(
            expect.objectContaining({ description: insertedTodo.description, category: insertedTodo.category })
          );
          done();
        });
    });
  });

and

   it('should create todo', async done => {
      const insertedTodo = todoCollection[0];
      mockRepoDependency({ createTodo: (todo: typeof insertedTodo) => Promise.resolve(todo) });

      const MockExpressServer = await import('./helpers/express-server-mock');
      const expressServer = new MockExpressServer.default();

      await expressServer.start();
      request(expressServer.app)
        .post('/v1/todo')
        .send(insertedTodo)
        .expect('Content-type', /json/)
        .end((err, res) => {
          expect(res.status).toEqual(201);
          const todoRes = res.body;
          expect(todoRes).toEqual(
            expect.objectContaining({ description: insertedTodo.description, category: insertedTodo.category })
          );
          done();
        });
      expressServer.stop();
    });
@silesky silesky changed the title OpenAPIValidation causes tests to fail intermittently integration tests fail intermittently with 400 Sep 25, 2019
@silesky silesky changed the title integration tests fail intermittently with 400 tests fail intermittently with 400 Sep 25, 2019
@cdimascio
Copy link
Owner

Interesting. Thanks for the details. Will have a look. If you find any additional info please pass it along. Curious if you have any additional insight as to where it may be going wrong. It sounds like a potentially shared instance of the validator or some internal validator state is used across all the express servers that you are spinning up. It would be fantastic if you are able to put together a simple example to demonstrate the problem. Having something reproducible certainly makes it easier to debug and resolve.

@cdimascio
Copy link
Owner

cdimascio commented Oct 22, 2019

@silesky i wonder if the fix for #81 might resolve this issue. would you mind trying out v2.8.1 to see if it solves it?

@cdimascio
Copy link
Owner

cdimascio commented Nov 2, 2019

closing this out due to inactivity. i believe this is resolved by #81
please reopen if this is not the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants