Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HaveField buffers stale fields #787

Closed
pohly opened this issue Oct 27, 2024 · 2 comments
Closed

HaveField buffers stale fields #787

pohly opened this issue Oct 27, 2024 · 2 comments

Comments

@pohly
Copy link

pohly commented Oct 27, 2024

I am using the following code to ensure that list.Items[] has exactly one element and that element has an empty Spec.Devices:

			emptySlice := gomega.HaveField("Spec.Devices", gomega.BeEmpty())
			gomega.Eventually(ctx, listSlices).WithTimeout(time.Minute).Should(gomega.HaveField("Items", gomega.ContainElements(emptySlice)))

My code under test incorrectly deleted all items (= list.Items[] empty). But the failure message then contained information about some previous item:

  [FAILED] Timed out after 60.000s.
  Value for field 'Items' failed to satisfy matcher.
  Expected
      <[]v1alpha3.ResourceSlice | len:0, cap:0>: nil
  to contain elements
      <[]*matchers.HaveFieldMatcher | len:1, cap:1>: [
          {
              Field: "Spec.Devices",
              Expected: 
                  {},
              extractedField: <[]v1alpha3.Device | len:128, cap:170>[
                  {
                      Name: "dev-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000",
                      Basic: {
                          Attributes: {
                              "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.example.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxx0010": {
                                  IntValue: nil,
                                  BoolValue: nil,
                                  StringValue: "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv",
                                  VersionValue: nil,
                              },
...

  Gomega truncated this representation as it exceeds 'format.MaxLength'.
  Consider having the object provide a custom 'GomegaStringer' representation
  or adjust the parameters in Gomega's 'format' package.

@onsi
Copy link
Owner

onsi commented Oct 29, 2024

ah. subtle. so the outer HaveField matcher is being polled and when it successfully fins .Items it passes the value of that field to ContainElements which then passes it to the inner HaveField. when the code deleted the items the out HaveField matcher failed early and did nto pass nil in to ContainElements.

The problem is that HaveField, the inner HaveField in particular, memoizes the extractedField and expectedMatcher so that it can render failure messages without having to redo the expensive (?) logic of extracting the field. I can remove this optimization, though, and then you won't get this stale and confusing detail in the output.

@onsi
Copy link
Owner

onsi commented Oct 29, 2024

done. will cut a release soon. i expect this change to be stable and the performance impact to be limited but please let me know if you see anything suspicious!

@onsi onsi closed this as completed in 3bdbc4e Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants