Skip to content

Flaky google.protobuf.Struct matching #71

@becdot

Description

@becdot

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsmartbear-supportedIssues with this label have been added to the Pactflow team's Jira backlog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions