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] local unit tests failed #2459

Closed
ananzh opened this issue Sep 29, 2022 · 4 comments
Closed

[Test] local unit tests failed #2459

ananzh opened this issue Sep 29, 2022 · 4 comments
Assignees
Labels
bug Something isn't working test:unit

Comments

@ananzh
Copy link
Member

ananzh commented Sep 29, 2022

See some failing unit tests from local development. CI is fine. Here is a summary of all the failing test cases:

Summary of all failing tests
 FAIL  src/plugins/data_source/server/cryptography/cryptography_client.test.ts
  ● Test encrpyt and decrypt module › Positive test cases › Encrypt and Decrypt with same in memory keyring

    Unsupported plaintext

      55 |    */
      56 |   public async encryptAndEncode(plainText: string): Promise<string> {
    > 57 |     const result = await this.encrypt(this.keyring, plainText);
         |                               ^
      58 |     return result.result.toString(ENCODING_STRATEGY);
      59 |   }
      60 |

      at Object.encrypt (node_modules/@aws-crypto/encrypt-node/src/encrypt.ts:54:11)
      at CryptographyClient.encryptAndEncode (src/plugins/data_source/server/cryptography/cryptography_client.ts:57:31)
      at Object.<anonymous> (src/plugins/data_source/server/cryptography/cryptography_client.test.ts:32:50)

  ● Test encrpyt and decrypt module › Positive test cases › Encrypt and Decrypt with two different keyrings with exact same identifiers

    Unsupported plaintext

      55 |    */
      56 |   public async encryptAndEncode(plainText: string): Promise<string> {
    > 57 |     const result = await this.encrypt(this.keyring, plainText);
         |                               ^
      58 |     return result.result.toString(ENCODING_STRATEGY);
      59 |   }
      60 |

      at Object.encrypt (node_modules/@aws-crypto/encrypt-node/src/encrypt.ts:54:11)
      at CryptographyClient.encryptAndEncode (src/plugins/data_source/server/cryptography/cryptography_client.ts:57:31)
      at Object.<anonymous> (src/plugins/data_source/server/cryptography/cryptography_client.test.ts:42:51)

  ● Test encrpyt and decrypt module › Negative test cases › Encrypt and Decrypt with different key names

    Unsupported plaintext

      55 |    */
      56 |   public async encryptAndEncode(plainText: string): Promise<string> {
    > 57 |     const result = await this.encrypt(this.keyring, plainText);
         |                               ^
      58 |     return result.result.toString(ENCODING_STRATEGY);
      59 |   }
      60 |

      at Object.encrypt (node_modules/@aws-crypto/encrypt-node/src/encrypt.ts:54:11)
      at CryptographyClient.encryptAndEncode (src/plugins/data_source/server/cryptography/cryptography_client.ts:57:31)
      at Object.<anonymous> (src/plugins/data_source/server/cryptography/cryptography_client.test.ts:65:51)

  ● Test encrpyt and decrypt module › Negative test cases › Encrypt and Decrypt with different key namespaces

    Unsupported plaintext

      55 |    */
      56 |   public async encryptAndEncode(plainText: string): Promise<string> {
    > 57 |     const result = await this.encrypt(this.keyring, plainText);
         |                               ^
      58 |     return result.result.toString(ENCODING_STRATEGY);
      59 |   }
      60 |

      at Object.encrypt (node_modules/@aws-crypto/encrypt-node/src/encrypt.ts:54:11)
      at CryptographyClient.encryptAndEncode (src/plugins/data_source/server/cryptography/cryptography_client.ts:57:31)
      at Object.<anonymous> (src/plugins/data_source/server/cryptography/cryptography_client.test.ts:84:51)

  ● Test encrpyt and decrypt module › Negative test cases › Encrypt and Decrypt with different wrapping keys

    Unsupported plaintext

      55 |    */
      56 |   public async encryptAndEncode(plainText: string): Promise<string> {
    > 57 |     const result = await this.encrypt(this.keyring, plainText);
         |                               ^
      58 |     return result.result.toString(ENCODING_STRATEGY);
      59 |   }
      60 |

      at Object.encrypt (node_modules/@aws-crypto/encrypt-node/src/encrypt.ts:54:11)
      at CryptographyClient.encryptAndEncode (src/plugins/data_source/server/cryptography/cryptography_client.ts:57:31)
      at Object.<anonymous> (src/plugins/data_source/server/cryptography/cryptography_client.test.ts:103:51)


Test Suites: 1 failed, 1 skipped, 1495 passed, 1496 of 1497 total
Tests:       5 failed, 24 skipped, 9 todo, 11329 passed, 11367 total
Snapshots:   2504 passed, 2504 total
Time:        136.72 s
@noCharger
Copy link
Contributor

Running single suite passed.

yarn test:jest src/plugins/data_source/server/cryptography/cryptography_client.test.ts 
yarn run v1.22.19
$ node scripts/jest src/plugins/data_source/server/cryptography/cryptography_client.test.ts
 PASS  src/plugins/data_source/server/cryptography/cryptography_client.test.ts
  ✓ Invalid wrapping key size throws error (4 ms)
  Test encrpyt and decrypt module
    Positive test cases
      ✓ Encrypt and Decrypt with same in memory keyring (59 ms)
      ✓ Encrypt and Decrypt with two different keyrings with exact same identifiers (31 ms)
    Negative test cases
      ✓ Encrypt and Decrypt with different key names (35 ms)
      ✓ Encrypt and Decrypt with different key namespaces (41 ms)
      ✓ Encrypt and Decrypt with different wrapping keys (29 ms)

Test Suites: 1 passed, 1 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        3.558 s, estimated 7 s
Ran all test suites matching /src\/plugins\/data_source\/server\/cryptography\/cryptography_client.test.ts/i.
✨  Done in 9.71s.

Running multiple suites serially also passed.

% yarn test:jest:ci src/plugins/data_source/server
yarn run v1.22.19
$ node scripts/jest --ci --colors --runInBand src/plugins/data_source/server
 PASS  src/plugins/data_source/server/cryptography/cryptography_client.test.ts
 PASS  src/plugins/data_source/server/client/configure_client.test.ts
 PASS  src/plugins/data_source/server/client/client_pool.test.ts
 PASS  src/plugins/data_source/server/client/client_config.test.ts
 PASS  src/plugins/data_source/server/lib/error.test.ts
 PASS  src/plugins/data_source/server/legacy/configure_legacy_client.test.ts
 PASS  src/plugins/data_source/server/legacy/client_config.test.ts
 PASS  src/plugins/data_source/server/data_source_service.test.ts

Test Suites: 8 passed, 8 total
Tests:       19 passed, 19 total
Snapshots:   0 total
Time:        9.061 s, estimated 13 s
Ran all test suites matching /src\/plugins\/data_source\/server/i.
✨  Done in 12.23s.

Seems to be a race condition when there's a worker pool of child processes that run tests. Need to dive deep.

@noCharger
Copy link
Contributor

noCharger commented Sep 30, 2022

Created Jest issue jestjs/jest#13349

I couldn't find much public information about how jest passes global configs when creating child processes. I'll also look into the Jest codebase for more information.

@ananzh
Copy link
Member Author

ananzh commented Apr 11, 2023

I think we could close it now. I don't see any local failed unit tests.

@ananzh ananzh closed this as completed Apr 11, 2023
@davidyuk
Copy link

We had the same issue using

  globals: {
    Uint8Array: Uint8Array,
  },

workaround I find is to add Uint8Array = Buffer.__proto__ to a file referenced in setupFiles instead of globals option from the above.

https://jestjs.io/docs/configuration#globals-object
Also, Jest suggests using setupFiles over globals if we need to put an object or function there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test:unit
Projects
None yet
Development

No branches or pull requests

3 participants