pactflow / pact-protobuf-plugin

Pact plugin for Protobufs and gRPC
MIT License
16 stars 8 forks source link

Flaky `google.protobuf.Struct` matching #71

Closed becdot closed 1 month ago

becdot commented 2 months ago

Hi! I have a question about struct matching, and I'm feeling kind of stumped. I have a proto with a struct field, e.g.

message Request {
  string name = 1;
  google.protobuf.Struct params = 2;
}

In my test, I am creating a new struct

params, err := structpb.NewStruct(map[string]any{"kind": "general", "message": "test" })

and then marshaling it to JSON. The string I am passing to withContents looks like this

{"pact:proto":"whatever.proto","pact:proto-service":"Service/Endpoint","pact:content-type":"application/protobuf","request":{"name":"name","params":{"kind":"general","message":"test"}},"response":{"responses":[{"success":true,"id":"test123"}]}}

I run the test once and get this error

Received generate templates error rpc error: code = FailedPrecondition desc = Failed to match the request message - BodyMismatches({"$.params": [BodyMismatch { path: "$.params.fields.key", expected: Some(b"\"message\""), actual: Some(b"\"kind\""), mismatch: "Expected 'kind' (String) to be equal to 'message' (String)" }, BodyMismatch { path: "$.params.fields.value.string_value", expected: Some(b"\"test\""), actual: Some(b"\"general\""), mismatch: "Expected 'general' (String) to be equal to 'test' (String)" }]})

and then I run the test again (changing nothing, with exact same contents string) and it passes.

My best guess is that something weird is happening with ordering – I dug into the trace logs, and as far as I could tell, sometimes the matching code finds the keys in the order ABAB (works) and sometimes it finds the keys in the order ABBA (doesn't work).

Let me know if I can provide additional logs / info – thanks so much for taking a look!

github-actions[bot] commented 2 months ago

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-2313). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

rholshausen commented 2 months ago

0.5.1 released with a fix for this

becdot commented 1 month ago

Amazing, thank you! 🥰

YOU54F commented 1 month ago

Hey @becdot, are you able to confirm if this resolves for you, when you are able to upgrade. ty!

becdot commented 1 month ago

@YOU54F yes, thank you for following up! Just added a few extra keys to my struct and ran the test several times and we seem to be golden!

YOU54F commented 1 month ago

lovely stuff. Thanks for the fix @rholshausen