Skip to content

Maintenance: avoid fixed-time waiting in our E2E testings #644

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

Closed
ijemmy opened this issue Mar 8, 2022 · 4 comments
Closed

Maintenance: avoid fixed-time waiting in our E2E testings #644

ijemmy opened this issue Mar 8, 2022 · 4 comments
Labels
automation This item relates to automation completed This item is complete and has been merged/shipped tests PRs that add or change tests

Comments

@ijemmy
Copy link
Contributor

ijemmy commented Mar 8, 2022

Bug description

Currently, our E2E tests are very flaky (fail about 40-50% of the time) due to fixed waiting time. This happens in both metrics and tracers E2E tests.

For example, tracer.test.ts waits for 2 minutes before finishing the beforeAll() function.

image

Sometimes, the trace come back later than two minutes. The test() blocks will fail.

Expected Behavior

The tests should not be flaky.

Current Behavior

The tests are flaky. If the traces/metrics appear after the fixed wait time.

Possible Solution

  1. Implement retry The tests should never wait for fixed amount of time. Instead, it should poll for trace or metrics and retry until it gets expected number of traces. This could be implemented with promise-retry library. See example code in "Reference" section below

  2. Introduce uuid However, we cannot simply count the number of traces or metrics because there might be another test running concurrently (e.g. one for Node14, another for Node12) . The traces/metrics found may be from another test running. Thus, we need to introduce a uuid in metadata and filter base on that. You can pass UUID via environment variable like in this e2e test in Logger

If you need refactoring, take note of Logger's e2e tests and try to structure it similar to that.

Steps to Reproduce

Run E2E tests a few times. You can use this script:

repeat 20 {jest --group=e2e/PACKAGE; sleep 0.5}

Environment

  • Powertools version used:0.7.0
  • Packaging format (Layers, npm): N/A
  • AWS Lambda function runtime: 12 and 14
  • Debugging logs: N/A

Related issues, RFCs

N/A

Reference

Here's an example implementation on fetching log stream with promise-retry library. It keep fetching until the log group has the atLeast number of log stream. You can adapt this with traces/metrics. (but need to check uuid)

export const fetchStreamsUntil = async (logGroupName: string, atLeast:number): Promise<string[]> => {
  const retryOption = {
    retries: 6,
    factor: 1.5,
    minTimeout: 1000, 
  }
  return promiseRetry(async (retry: any, attemptNumber: number) => {
    const streams = await fetchStreams(logGroupName)
    if(streams.length < atLeast){
      console.debug(`Found ${streams.length} log streams, retry until having at least ${atLeast} stream`);
      retry();
    }
    return streams;
  }, retryOption)
};
@ijemmy ijemmy added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Mar 8, 2022
@ijemmy ijemmy assigned ijemmy and unassigned ijemmy Mar 8, 2022
@ijemmy
Copy link
Contributor Author

ijemmy commented Mar 8, 2022

Discussed with @AWSDB . He'll take this issue.

@dreamorosi
Copy link
Contributor

@AWSDB could you leave a comment so I can assign the issue to you? (apologies for bothering you with this but GitHub doesn't let me add you if you haven't interacted with the issue first).

@ghost
Copy link

ghost commented Mar 9, 2022

@dreamorosi That's strange. Anyway, here's my comment - happy to work on this issue!

@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi removed the triage This item has not been triaged by a maintainer, please wait label Oct 19, 2022
@dreamorosi dreamorosi changed the title Bug (metrics, tracer): avoid fixed-time waiting in our E2E testings Maintenance: avoid fixed-time waiting in our E2E testings Nov 14, 2022
@dreamorosi dreamorosi added automation This item relates to automation tests PRs that add or change tests completed This item is complete and has been merged/shipped and removed bug Something isn't working labels Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation This item relates to automation completed This item is complete and has been merged/shipped tests PRs that add or change tests
Projects
None yet
Development

No branches or pull requests

3 participants