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

[bug]: keploy tests are failing with the Prisma ORM #1944

Closed
1 task done
Sonichigo opened this issue Jun 7, 2024 · 2 comments
Closed
1 task done

[bug]: keploy tests are failing with the Prisma ORM #1944

Sonichigo opened this issue Jun 7, 2024 · 2 comments
Labels
bug Something isn't working keploy

Comments

@Sonichigo
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hi Team! My Keploy tests just crashed. This is the report:

Versions

Name Version
Node v21.6.0
OS Linux lima-default 6.1.0-21-cloud-arm64#1 SMP Debian 6.1.90-1 (2024-05-03) aarch64 GNU/Linux
Prisma Client 5.12.1
Query Engine 473ed3124229e22d881cb7addf559799debae1ab
Database postgresql
Bun Version 1.1.4
Keploy 2.1.0-alpha23

When I am running Keploy test -c "bun --watch index.ts" i get error : -

🐰 Keploy: 2024-06-06T18:08:12Z         INFO    starting test for of    {"test case": "test-1", "test set": "test-set-6"}
thread 'tokio-runtime-worker' panicked at query-engine/connectors/sql-query-connector/src/database/operations/write.rs:194:22:
Could not figure out an ID in create
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Testrun failed for testcase with id: "test-1"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-1                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                 Content-Length: [216]                |               Content-Length: [2935]                 |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|    {                                                 |  {                                                   |
|   -  "user": {                                       | +  "error": "                                        |
|   -    "createdAt": "2024-06-06T18:06:49.995Z",      | Invalid `prisma.user.create()` invocation in         |
|   -    "email": "isssalcupnamde@abc.com",            | /workspaces/Blog-Website/services/user.service.ts:   |
|   -    "id": 1,                                      | 19:12                                                |
|   -    "name": "Yash",                               |   16 });                                             |
|   -    "password": "$2b$10$sORFubjTUt8Mt2k7vNqt4O3VV |                                                

Initally, I thought the issue is with Prisma client but it seems that the keploy is not returning correct mocks to prisma which leads to the test failures. So i tried to run with --removeUnsedMocks, in this case out of 4 testcases randomly I'm able to get correct reponse.

Attempt#1

Testrun failed for testcase with id: "test-3"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-3                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|    {                                                 |  {                                                   |
|      "recipe": {                                     |    "recipe": {                                       |
|        "body": "AOT from quantum universe",          |      "body": "AOT from quantum universe",            |
|   -    "createdAt": "2024-06-06T10:50:06.885Z",      | +    "createdAt": "2024-06-07T09:52:52.929Z",        |
|   -    "id": 1,                                      | +    "id": 7,                                        |
|        "title": "Anime",                             |      "title": "Anime",                               |
|   -    "updatedAt": "2024-06-06T10:50:06.885Z",      | +    "updatedAt": "2024-06-07T09:52:52.929Z",        |
|        "userId": 1                                   |      "userId": 1                                     |
|      }                                               |    }                                                 |
|    }                                                 |  }                                                   |
|                                                      |                                                      |
|                                                                                                             |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    result  {"testcase id": "test-3", "testset id": "failed", "passed": "false"}
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    starting test for of    {"test case": "test-4", "test set": "failed"}

Attempt#2

🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    starting test for of    {"test case": "test-1", "test set": "failed"}
Testrun failed for testcase with id: "test-1"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-1                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                 Content-Length: [216]                |               Content-Length: [111]                  |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|    {                                                 |  {                                                   |
|   -  "user": {                                       | +  "error": "                                        |
|   -    "createdAt": "2024-06-06T10:49:32.314Z",      | Invalid `prisma.user.create()` invocation:           |
|   -    "email": "isssalcupnamde@abc.com",            | Unique constraint failed on the fields: (`email`)"   |
|   -    "id": 1,                                      |  }                                                   |
|   -    "name": "Yash",                               |                                                      |
|   -    "password": "$2b$10$4ywzTTTucw2MgU20xjWGR.Ja7 |                                                      |
|   H09jWVC05WaRMiF9qiiKu4px/qxW",                     |                                                      |
|   -    "updatedAt": "2024-06-06T10:49:32.314Z"       |                                                      |
|   -  }                                               |                                                      |
|   Invalid `prisma.user.create()` invocation:         |                                                      |
|   Unique constraint failed on the fields: (`email`)" |                                                      |
|    }                                                 |                                                      |
|                                                      |                                                      |
|                                                                                                             |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    result  {"testcase id": "test-1", "testset id": "failed", "passed": "false"}
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    starting test for of    {"test case": "test-2", "test set": "failed"}
Testrun failed for testcase with id: "test-2"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-2                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|    {                                                 |  {                                                   |
|      "message": "User logged in successfully",       |    "message": "User logged in successfully",         |
|   -  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. | +  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.   |
|   eyJpZCI6MSwiZW1haWwiOiJpc3NzYWxjdXBuYW1kZUBhYmMuY2 | eyJpZCI6MSwiZW1haWwiOiJpc3NzYWxjdXBuYW1kZUBhYmMuY2   |
|   9tIiwiaWF0IjoxNzE3NjcwOTg0LCJleHAiOjE3MTc3NTczODR9 | 9tIiwiaWF0IjoxNzE3NzUzOTcyLCJleHAiOjE3MTc4NDAzNzJ9   |
|   .Q1aIVnLTil15EnCa441tW6fi5ler--0mJheGigPCX18"      | .3PUY7-Zj71eg5r209S5P4wWyExXLRAsaD7Caj9PfYmQ"        |
|    }                                                 |  }                                                   |
|                                                      |                                                      |
|                                                                                                             |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    result  {"testcase id": "test-2", "testset id": "failed", "passed": "false"}
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    starting test for of    {"test case": "test-3", "test set": "failed"}
Testrun failed for testcase with id: "test-3"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-3                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|    {                                                 |  {                                                   |
|      "recipe": {                                     |    "recipe": {                                       |
|        "body": "AOT from quantum universe",          |      "body": "AOT from quantum universe",            |
|   -    "createdAt": "2024-06-06T10:50:06.885Z",      | +    "createdAt": "2024-06-07T09:52:52.929Z",        |
|   -    "id": 1,                                      | +    "id": 7,                                        |
|        "title": "Anime",                             |      "title": "Anime",                               |
|   -    "updatedAt": "2024-06-06T10:50:06.885Z",      | +    "updatedAt": "2024-06-07T09:52:52.929Z",        |
|        "userId": 1                                   |      "userId": 1                                     |
|      }                                               |    }                                                 |
|    }                                                 |  }                                                   |
|                                                      |                                                      |
|                                                                                                             |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    result  {"testcase id": "test-3", "testset id": "failed", "passed": "false"}
🐰 Keploy: 2024-06-07T15:22:52+05:30    INFO    starting test for of    {"test case": "test-4", "test set": "failed"}
Testrun failed for testcase with id: "test-4"

--------------------------------------------------------------------

+-------------------------------------------------------------------------------------------------------------+
|                                                DIFFS TEST-4                                                 |
+-------------------------------------------------------------------------------------------------------------+
|                     EXPECT HEADER                    |                   ACTUAL HEADER                      |
| -----------------------------------------------------+----------------------------------------------------- |
|                 Content-Length: [379]                |                Content-Length: [2]                   |
|                                                      |                                                      |
|                                                                                                             |
|                      EXPECT BODY                     |                    ACTUAL BODY                       |
| -----------------------------------------------------+----------------------------------------------------- |
|   [{"id":1,"title":"Anime","body":"AOT from quantum  | []                                                   |
|   universe","createdAt":"2024-06-06T10:50:06.885Z"," |                                                      |
|   updatedAt":"2024-06-06T10:50:06.885Z","userId":1," |                                                      |
|   user":{"id":1,"email":"isssalcupnamde@abc.com","na |                                                      |
|   me":"Yash","password":"$2b$10$4ywzTTTucw2MgU20xjWG |                                                      |
|   R.Ja7H09jWVC05WaRMiF9qiiKu4px/qxW","createdAt":"20 |                                                      |
|   24-06-06T10:49:32.314Z","updatedAt":"2024-06-06T10 |                                                      |
|   :49:32.314Z"},"comments":[]}]                      |                                                      |
|                                                      |                                                      |
|                                                                                                             |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-06-07T15:22:53+05:30    INFO    result  {"testcase id": "test-4", "testset id": "failed", "passed": "false"}

 <=========================================> 

Out of 20 attempts only attempt#2 had most acurrate and nearest results.

Steps to reproduce

Here's my repo:- https://github.com/darkin424/Blog-Website .

To reproduce please follow the steps below:-

1. start the database docker instance
2. install `keploy` with :- https://keploy.io/docs/server/installation/
3. keploy record -c "bun --watch index.ts"
4. make few post api call for creation like `signup`, `create-post`
5. stop the docker instance
6. keploy test -c "bun --watch index.ts"

The API Calls : -

## Create a User
curl --location 'http://localhost:4040/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"Yash",
    "email":"isssalcupnamde@abc.com",
    "password":"1234"
}'

## Login 

curl --location 'http://localhost:4040/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email":"isssalcupnamde@abc.com",
    "password":"1234"
}'

## Create a Post
## You can get <TOKEN> from above curl response

curl --location 'http://localhost:4040/create-post' \
--header 'Authorization: Bearer <TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
    "title":"Anime",
    "body":"AOT from quantum"
}'

Environment

Release

Version

Local

Repository

keploy

@gouravkrosx
Copy link
Member

gouravkrosx commented Jun 27, 2024

@Sonichigo Can you please check again with the latest version of keploy? and close this issue if it works for you.

@Sonichigo
Copy link
Member Author

With latest keploy this issue is resolved! @gouravkrosx @PranshuSrivastava thanks for the resolving this issue

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

No branches or pull requests

2 participants