Skip to content

[Service Bus] Update Delays in Streaming Receiver#1214

Merged
ramya-rao-a merged 22 commits intoAzure:masterfrom
HarshaNalluru:DelaysSR
Feb 15, 2019
Merged

[Service Bus] Update Delays in Streaming Receiver#1214
ramya-rao-a merged 22 commits intoAzure:masterfrom
HarshaNalluru:DelaysSR

Conversation

@HarshaNalluru
Copy link
Contributor

Issue
#1147

Description

  • Can reuse the DelayStreaming function in all the streaming receiver tests
  • Fixed number of iterations is being changed to maxDelay
  • delayBetweenRetries, maxDelay are constants and will remain same for all the tests (easier to update them if needed)
  • This new function can be used anywhere (not just for streaming receiver)

All the tests in Streaming Receiver passed after the changes(local).
Thanks to @mikeharder - #1147 (comment) .

@HarshaNalluru HarshaNalluru added Client This issue points to a problem in the data-plane of the library. Service Bus labels Feb 13, 2019
@HarshaNalluru HarshaNalluru self-assigned this Feb 13, 2019
@ghost ghost added the in progress label Feb 13, 2019
Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

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

Lets do the same in all tests that use the streaming receiver

should.equal(msgsCheck, true, "Could not receive the messages in expected time.");
should.equal(unexpectedError, undefined, unexpectedError && unexpectedError.message);

should.equal(receivedMsgs.length, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we shouldnt remove this check.
What if we got more than 1? then the test should fail isnt it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for other cases where we are removing the check

Copy link
Contributor Author

@HarshaNalluru HarshaNalluru Feb 15, 2019

Choose a reason for hiding this comment

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

The only way we can get more than 1 message is we receive a message after receivedMsgs.length === 1 is verified.
Then, we should also give more scope to receive messages - instead of returning true right after the receivedMsgs.length === 1 check, we can add await delay(retry)[in the DelayStreaming module] and then return true.
Does this make sense ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thats ok, we can keep it the way it is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ramya-rao-a You want me keep this should.equal(receivedMsgs.length, 1); ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Github is acting weird... I am adding a reply to one comment thread.. it is appearing in another :)

When waiting for the 1 sec inside the loop, it can happen that the receiver gets the second message. So, we should keep the should.equal(receivedMsgs.length, 1) check

Copy link
Contributor Author

@HarshaNalluru HarshaNalluru Feb 15, 2019

Choose a reason for hiding this comment

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

We are not waiting for 1 sec inside the loop.

export async function checkWithTimeout(
  predicate: () => boolean,
  delayBetweenRetriesInMilliseconds: number = 1000,
  maxWaitTimeInMilliseconds: number = 10000
): Promise<boolean> {
  const maxTime = Date.now() + maxWaitTimeInMilliseconds;
  while (Date.now() < maxTime) {
    if (predicate()) return true;
    await delay(delayBetweenRetriesInMilliseconds);
  }
  return false;
}
  • We return true as soon as receivedMsgs.length becomes 1.
  • The only way we can get more than 1 message is if we receive a message after receivedMsgs.length === 1 is verified.

I suggest we add a await delay(delayBetweenRetriesInMilliseconds);
just before we return true and then keep the check should.equal(receivedMsgs.length, 1); in the tests.

Updated checkWithTimeout looks like

export async function checkWithTimeout(
  predicate: () => boolean,
  delayBetweenRetriesInMilliseconds: number = 1000,
  maxWaitTimeInMilliseconds: number = 10000
): Promise<boolean> {
  const maxTime = Date.now() + maxWaitTimeInMilliseconds;
  while (Date.now() < maxTime) {
    if (predicate()){
        await delay(delayBetweenRetriesInMilliseconds);
        return true;
    } 
    await delay(delayBetweenRetriesInMilliseconds);
  }
  return false;
}

My only concern with this is, it basically increases the the time taken by each test by 1 second.

Copy link
Member

Choose a reason for hiding this comment

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

checkWithTimeout() should definitely return immediately when the predicate is true.

mikeharder
mikeharder previously approved these changes Feb 15, 2019
Copy link
Member

@mikeharder mikeharder left a comment

Choose a reason for hiding this comment

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

My feedback is limited to testUtils.ts. The code looks correct to me. I suggested a few optional naming changes.

Copy link
Member

@mikeharder mikeharder left a comment

Choose a reason for hiding this comment

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

Changing my review from "approve" to "comment"

@mikeharder mikeharder dismissed their stale review February 15, 2019 01:42

Meant to review as "comment" instead of "approve"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client This issue points to a problem in the data-plane of the library. Service Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants