hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Eager caching not behaving as anticipated.

Open colts45s opened this issue 3 years ago • 4 comments

After loading configuration.json, cache is null.

Steps to reproduce the issue

  1. Start Hoverfly in capture mode
  2. Run traffic through the proxy and capture both request and responses
  3. Export configuration.json
  4. Stop Hoverfly
  5. Start Hoverfly in Simulation mode (Found webserver and proxy to behave identically)
  6. Import configuration
  7. Check cache.

Observed result

None

Cache is null

Expected result

Cache populated with the configuration data in an eager fashion rather than lazy loading

Additional relevant information

  1. Hoverfly version: 1.3.0
  2. I found the same behavior if switching from capture to simulate in the same instance. To get a cached request response pair I would have to execute the call in capture, change to simulation, then re-run the request to populate the cache.

colts45s avatar Jan 27 '22 20:01 colts45s

@colts45s this is a bug actually, so what happens is that the eager caching function is only called when you run hoverctl mode simulate, but it's not executed when hoverfly starts 🤦

The workaround is that after step 5 in your example, you call hoverctl mode simulate and it should force the cache preloading.

tommysitu avatar Feb 07 '22 20:02 tommysitu

I attempted this work around and was unable to achieve eager caching, I have a valid configuration.json file and even after i explicitly set the mode to simulate, loading the configuration does not add any items to the cache.

colts45s avatar Feb 08 '22 19:02 colts45s

ok, the problem is this function checks eagerly cacheable simulation always return nil 😞 https://github.com/SpectoLabs/hoverfly/blob/master/core/models/request_matcher.go#L207

tommysitu avatar Feb 08 '22 20:02 tommysitu

https://github.com/SpectoLabs/hoverfly/pull/1006 should fix the workaround at least

tommysitu avatar Feb 08 '22 23:02 tommysitu

@colts45s raised PR to fix this issue.

kapishmalik avatar Mar 12 '23 13:03 kapishmalik

@colts45s this is done. You can check and let us know incase of any concerns.

kapishmalik avatar Mar 17 '23 03:03 kapishmalik

@tommysitu you can close this issue.

kapishmalik avatar Mar 18 '23 18:03 kapishmalik

This has been fixed since https://github.com/SpectoLabs/hoverfly/releases/tag/v1.5.2

tommysitu avatar Nov 28 '23 22:11 tommysitu