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

Intermittent strings.Join bug. #2

Closed
geekodour opened this issue Nov 7, 2024 · 3 comments
Closed

Intermittent strings.Join bug. #2

geekodour opened this issue Nov 7, 2024 · 3 comments

Comments

@geekodour
Copy link

I think this is related to the output generation done by testy. As you can see the issue is with key r_uploadfile_019304d6-5500-7d19-b728-7f0fac31c88d but it seems to fine in the debug print I did in the test(see below). Most times it succeeds but sometimes the test errors out with this. (this can be reproduced in isolation for that particular test). I am not sure where strings.Join is coming from.

=== PAUSE TestWorkflowBuildDag
=== CONT  TestWorkflowBuildDag
    workflow_test.go:18: testdbconf: postgres://pgtdb-superuser:pgtdbpass@localhost:7777/testdb_tpl_411f891bfd1188057edf05e7f31734f9_inst_4fbcc93c?sslmode=disable
// NOTE: following is formatted for readablity
&{
map[
r_fieldmapper_019304d6-54fe-7c62-87dd-16db1821cd35:1
r_metaextract_019304d6-54ff-7ecf-8841-e0e10060d470:1
r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f:2
r_uploadfile_019304d6-5500-7d19-b728-7f0fac31c88d:0] 

map[
r_fieldmapper_019304d6-54fe-7c62-87dd-16db1821cd35:[r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f] r_metaextract_019304d6-54ff-7ecf-8841-e0e10060d470:[r_fieldmapper_019304d6-54fe-7c62-87dd-16db1821cd35] r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f:[]
r_uploadfile_019304d6-5500-7d19-b728-7f0fac31c88d:[
  r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f
  r_metaextract_019304d6-54ff-7ecf-8841-e0e10060d470]
]}

    workflow_test.go:51: expected want == got
        --- want
        +++ got
          workflow.DependentsMap{
                "r_fieldmapper_019304d6-54fe-7c62-87dd-16db1821cd35":  {"r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f"},
                "r_metaextract_019304d6-54ff-7ecf-8841-e0e10060d470":  {"r_fieldmapper_019304d6-54fe-7c62-87dd-16db1821cd35"},
                "r_templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f": {},
                "r_uploadfile_019304d6-5500-7d19-b728-7f0fac31c88d": {
                        strings.Join({
                                "r_",
        -                       "metaextract_019304d6-54ff-7ecf-8841-e0e10060d470",
        +                       "templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f",
                        }, ""),
                        strings.Join({
                                "r_",
        -                       "templatefill_019304d6-54fc-73a3-8059-374b3c9fdc8f",
        +                       "metaextract_019304d6-54ff-7ecf-8841-e0e10060d470",
                        }, ""),
                }
@geekodour
Copy link
Author

Hmm, now that i think this seems more like an ordering issue, but still I think some abstraction is getting leaked with the end user having to see strings.Join

@peterldowns
Copy link
Owner

peterldowns commented Nov 7, 2024

The strings.Join in the assertion output is how go-cmp sometimes chooses to report differences in long strings with many shared substrings. testy uses go-cmp to perform its equality comparisons. For some relevant discussion, see google/go-cmp#356. If you'd prefer to see the difference reported in another format, you can always pass a custom go-cmp.Reporter as an option, see their docs for more info.

The issue here is not due to testy or go-cmp; the test is failing due to an actual difference between two values being compared. If the two values are maps, then the issue may be due to key randomization, like you mentioned. Comparing maps in golang is annoying, sorry, my advice would be to rewrite your test/comparisons to avoid it if possible.

@peterldowns peterldowns closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2024
@peterldowns
Copy link
Owner

peterldowns commented Nov 7, 2024

You may be interested in the cmpopts.SortMaps option, as described in the cmp.Equal documentation:

Maps are equal if they are both nil or both non-nil, where recursively calling Equal on all non-ignored map entries report equal. Map keys are equal according to the == operator. To use custom comparisons for map keys, consider using github.com/google/go-cmp/cmp/cmpopts.SortMaps. Empty non-nil maps and nil maps are not equal; to equate empty maps, consider using github.com/google/go-cmp/cmp/cmpopts.EquateEmpty.

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