I have a test, that reads Auth Code from mailbox and uses it to log in. I use Gmail API for that.

I would like to have several such tests, that will run in parallel.

However, I don't know, how to distinguish emails from each other, because the only thing, that is different about 2 emails is this Auth Code.

So, race condition looks like this:

  1. test-1 sends an email at 00:00:00
  2. test-2 sends an email at 00:00:01
  3. it takes 3 seconds for the email-1 to arrive => 00:00:03,
  4. it takes only 1 second for the email-2 to arrive => 00:00:02
  5. test-1 reads the first unread matching email, and it is an email-2

Result: Auth code is wrong.

So, my question here is:

could you please think of any possible solution to avoid such a race condition and identify the email?

  • Didn't you consider using different emails for different threads?
    – Alexey R.
    Aug 18, 2020 at 18:33

2 Answers 2


Why don't you use different e-mail accoouns for this (of course if you are not going to test the case when user try to login two times and mix codes/use proper codes from two messages e.g. on 2 devices)?

  • 2
    How about using Gmails wildcard feature "myname+randomWildcard@gmail.com" and then distinguish based on "randomWildcard"? Aug 19, 2020 at 5:45

Some email providers let you use "+" on the email address, e. g. "johndoe+abc123@example.com" that you can use to differentiate the different sources.

Is the information on the source of the email buried in the headers that you can hunt?

Can your devs embed a hidden element in the page you see immediately after the email is sent, then include either a similar hidden element in the email? Or in a header? Bonus points if they can do this only on your testing systems, or if you can change the URL to add a query string parameter to trigger adding the debug information?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.