question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expectBody not working as expected

See original GitHub issue

Hi @mcollina my version “autocannon”: “^7.9.0”, my codebase

let customResponse= customResponse

  url: 'http://localhost:3011/employees/api/searchtype/',
  amount: 10,
  connections: 1,
  pipelining: 1,
  //duration: 60,
  method: "POST",
  debug: true,
  expectBody: customResponse,
  headers: { "Content-Type": "application/json; charset=UTF-8", 'x-access-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NTkxMjMxMTd9.xavjahsbNggTSDBu6Vmsxzz6olPMXHTPggkFForZqaU' },
  body: JSON.stringify(customRequest),

}, (err, result) => {

  console.log(err);
  if (err != null) return; // or do some error handling
  handleResults(result);
})

The response which i am getting from api response is below API Response

and when I compare it http://www.jsondiff.com/ it was identical Problem statement

when i run the above i am getting mismatched results which should not happen if both the customResponse and API Response are identical

Any pointers on how to tackle this issue

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
matt212commented, Jul 30, 2022

Hi @mcollina I have put together this repo with all required details to reproduce the issue

NodeJS_Fastify_AutoCannon

All instructions are spelled out in readme file for above repo

Cheers !

0reactions
matt212commented, Jul 31, 2022

Hi @mcollina

there is deeper problem wherein resp.body always is string so my below code will only work if resp.body follows actual api response type whether it is obj or string


filename : httpClient
path : autocannon\lib
line :  109

if (!isFn && this.opts.expectBody && this.opts.expectBody !== resp.body) {
        if (typeof resp.body === 'object') {         
          if (!compareObjects(this.opts.expectBody, resp.body) === false) {
            return this.emit('mismatch', resp.body)
          }
        } else if (typeof resp.body === 'string') {
          
          return this.emit('mismatch', resp.body)
        }
      }
    }

further investigation points to below const HTTPParser = require('http-parser-js').HTTPParser which parses and it seems convert all responses to string again that is as per my investigation correct me if i am wrong

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebTestClientExtensions.expectBody doesn't work ... - GitHub
Since WebTestClientExtensions.expectBody uses plain Class instead of ParameterizedTypeReference , it cannot correctly deserialize generic types.
Read more >
WebTestClient check that jsonPath contains sub string
I am using Spring Boot 2.7.5 and this works just fine. The currently selected correct answer might work but it is much more...
Read more >
WebTestClient$BodyContentSpec.jsonPath - Java - Tabnine
Assert the response body content with the given Consumer. json. Parse the expected and actual response content as JSON and perform a "lenient"...
Read more >
WebTestClient.ResponseSpec (Spring Framework 6.0.3 API)
Consume and decode the response body to a single object of type <B> and then apply assertions. Parameters: bodyType - the expected body...
Read more >
What To Expect - Body Gears Physical TherapyBody Gears
Kindly, expect the unmatched and unparalleled physical therapy and rehab ... a solid treatment regimen addressing not just your symptoms, but your problems....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found