pact-ruby icon indicating copy to clipboard operation
pact-ruby copied to clipboard

Recent versions of Oj (3.11.4 and 3.11.5) are causing issues with the Pact library

Open iamvery opened this issue 3 years ago • 6 comments

👋 I'll say up front that this was difficult to narrow down, and I'm still not certain of the root cause. It's unclear to me whether it's ultimately on the Oj or Pact side.

Problem

After updating to Oj 3.11.4 and 3.11.5, we are seeing intermittent test failures for Pact examples. The failures appear to be a result of how objects are serialized. On oj 3.11.3, responses present like:

{ "some_field" => #<Pact::SomethingLike...> }

But after upgrading certain responses later in test runs present like:

{ "some_field" => { "json_class" => "Pact::SomethingLike", ... }

Note: the issue is currently presenting itself for certain RSpec "seeds" and often happens after some successfully and correctly serialized response bodies. For example, the first Pact test will run correctly and successfully and a subsequent one is serialized incorrectly as shown above which results in failure.

Thank you for your work on this library, and please let me know if I can provide more information. Unfortunately at this time, I'm not certain how to reproduce the issue outside of our code and test suite, but I'm hopefully the reporting it may trigger some thought on recent changes.

» ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
» rails -v
Rails 6.1.3.1

See also https://github.com/ohler55/oj/issues/656

iamvery avatar Apr 27 '21 15:04 iamvery

Possibly related to this previous issue: https://github.com/pact-foundation/pact-ruby/issues/166

zorab47 avatar Apr 28 '21 13:04 zorab47

Thanks for the details. Until you can reproduce it reliably in a codebase you can share with me, I don't think there's much I can do to fix it unfortunately. My gut feeling based on the previous issues people have had, that you've already found, is that there will be a specific OJ setting that needs to be set to fix this.

bethesque avatar Apr 30 '21 07:04 bethesque

I tried removing our lock on Oj and running things again, and it appears that something in a recent release has fixed the issue.

iamvery avatar Jul 23 '21 15:07 iamvery

I spoke too soon. The failures are order dependent so a passing build gave me false confidence 😞

iamvery avatar Jul 23 '21 15:07 iamvery

For reference, a script to reproduce this is available here: https://gist.github.com/zorab47/f00e4ad8d5b02b583c2ba97db6011f67

iamvery avatar Jul 23 '21 16:07 iamvery

I'll have another look at it on my next OSS day.

bethesque avatar Jul 25 '21 23:07 bethesque

Thanks everyone for all the investigations and the excellent reproducer!

This is now resolved as per comments here

https://github.com/ohler55/oj/issues/656#issuecomment-1696028716

the original example has been updated.

tl;dr - if you use OJ, set Oj.default_options = { create_additions: true }

YOU54F avatar Aug 15 '24 17:08 YOU54F