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

Test that Enketo IDs are requested during request to create form #1001

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

matthew-white
Copy link
Member

@matthew-white matthew-white commented Sep 22, 2023

Follow-up PR to #989, adding more tests. Only test/ is changed, not lib/.

#989 included tests of requests to publish an existing form. This PR also tests requests to create a form (either as a draft form or as an immediately published form).

Before submitting this PR, please make sure you have:

  • run make test-full and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

const asAlice = await service.login('alice');
global.enketo.wait = (f) => { setTimeout(f, 501); };
global.enketo.wait = (done) => { setTimeout(done, 600); };
Copy link
Member Author

@matthew-white matthew-white Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from 501 to 600 is meant to address this intermittent test failure: #588 (comment). Note that this test was not introduced in #989, but rather #782. I don't think I did anything in #989 that would have changed the POST/GET …/draft endpoints. However, if this test is failing, it certainly seems possible that new tests in #989 could fail, so I think it's worth addressing now.

Here's one possible explanation for the failure:

  • A request to Enketo is sent. After 501 ms, the Enketo mock will respond.
  • A moment later, the endpoint time-bounds the request. After 500 ms has elapsed since that bounding, the endpoint will stop waiting for the request.
  • If "a moment later" is greater than 1 ms, then the test will fail.

Another possible explanation:

  • setTimeout() doesn't run callbacks after an exact number of milliseconds, but after at least the specified number of milliseconds. So the Enketo mock could respond after 502 ms instead of after 501 ms.
  • Similarly, the endpoint could stop waiting after 502 ms instead of after 500 ms.
  • In other words, both timers could exceed the number of milliseconds specified and maybe be processed together in a single batch of timers. In that case, the order in which the callbacks are run might be indeterminate.

I'm not sure what the exact explanation is, but the fact that the test is failing intermittently doesn't make me think that there's anything wrong with the functionality here. I think we just need to provide a little more wiggle room for the test.

.send(testData.forms.simple2)
.expect(200);
global.enketo.callCount.should.equal(1);
without(['token'], global.enketo.createData).should.eql({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to test the token argument at this time. Unlike in the draft case above, token won't be undefined. However, I'm not sure that the token is even needed for this flow to function: see #997. We don't test the token in existing tests.

@@ -24,6 +24,8 @@ const defaults = {
// The number of times that the mock has been called during the test, that is,
// the number of requests that would be sent to Enketo
callCount: 0,
// An object with a property for each argument passed to the create() method
createData: undefined,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added createData instead of using receivedUrl in the new tests here, for two reasons:

  • This allows us to test the xmlFormId argument of enketo.create() (the second argument), not just the first argument (openRosaUrl/receivedUrl).
  • Consistency with editData elsewhere in this file, which we use to test enketo.edit().

@matthew-white
Copy link
Member Author

@ktuite, I think this can be reviewed async, but let me know if you'd like to review interactively!

@matthew-white matthew-white merged commit 4a30211 into master Oct 6, 2023
4 checks passed
@matthew-white matthew-white deleted the enketo-id-tests branch October 6, 2023 20:55
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

Successfully merging this pull request may close these issues.

2 participants