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

Correct MakeRequests() output assertion in adapter JSON tests #2087

Merged

Conversation

guscarreon
Copy link
Contributor

@guscarreon guscarreon commented Nov 16, 2021

Current version of test framework function assertMakeRequestsOutput(t *testing.T, filename string, actual []*adapters.RequestData, expected []httpCall) throws a false negative when the order of the entries in the parameter slices actual and expected differ even when they come with matching elements. This pull request implements a correction that runs in O(n^2) time but, because tests are not run in production, we don't mind the extra processing time given that most tests come with slices of size 1 anyways.

}
expectedHeader, err := json.Marshal(expected.Headers)
if err != nil {
return fmt.Errorf(`%s expected.Headers could not be marshalled. Error: %s"`, description, err.Error())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ignoring marshalling errors anymore. (If any)

}
if len(actual) == 0 || len(expected) == 0 {
t.Fatalf("%s json diff failed. Expected %d bytes in body, but got %d.", description, len(expected), len(actual))
return fmt.Errorf("%s json diff failed. Expected %d bytes in body, but got %d.", description, len(expected), len(actual))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that diffJson() returns an error, no need to differentiate this error asFatalf over Errorf. This particular JSON test won't continue to run because our test framework will simply go to the next JSON file in the directory.

@@ -263,60 +282,54 @@ func diffBids(t *testing.T, description string, actual *adapters.TypedBid, expec
return
}

diffStrings(t, fmt.Sprintf("%s.type", description), string(actual.BidType), string(expected.Type))
diffOrtbBids(t, fmt.Sprintf("%s.bid", description), actual.Bid, expected.Bid)
assert.Equal(t, string(expected.Type), string(actual.BidType), fmt.Sprintf(`%s.type "%s" does not match expected "%s."`, description, string(actual.BidType), string(expected.Type)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for diffStrings() anymore

}

diffStrings(t, fmt.Sprintf("%s.uri", description), actual.Uri, expected.Uri)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for diffStrings() anymore

for j := 0; j < len(actual); j++ {
if err = diffHttpRequests(fmt.Sprintf("%s: httpRequest[%d]", filename, i), actual[j], &(expected[i].Request)); err == nil {
break
}
Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this approach. Please correct me if I'm wrong. For example it may not work correctly in case expected has 2 same exact requests (IDK if this is the case) and actual has also 2 requests, first one is correct and second one is empty(or different/incorrect). Bacause you start iteration over actual from the beginning - such case will pass.
I feel like you need to remove matched actual request from collection after it matched before iterating over it again.
I was not able to create a unit tests for this, becuse in most cases we only have 1 expected request. I can try to do this when 33across changes will be merged.
This test needs a test :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Veronika is correct in bringing up this example that wouldn't work. I'm also not sure if this behavior of 2 same requests is possible, but the solution to remove matched request from list makes sense to me!

Another idea could be to maybe convert expected and actual lists to be maps, which could make the comparison of these objects faster in general and solve the issue Veronika brought up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexBVolcy Maps instead of a nested for loop was my first choice but I tried map[string]*RequestData but couldn't get the keys to match. Maybe I need to try again because I definitely like the hash table approach better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this approach. Please correct me if I'm wrong. For example it may not work correctly in case expected has 2 same exact requests (IDK if this is the case) and actual has also 2 requests, first one is correct and second one is empty(or different/incorrect).

You are right, this approach was implemented under the assumption that the expected entries at least differ in the root.imp[i].id fields but a corner case should be considered where this is not true. I'll give the remove matched actual request approach a try.

@curlyblueeagle
Copy link
Contributor

Added test looks good

@mansinahar mansinahar merged commit 287aa6c into prebid:master Nov 23, 2021
wwwyyy pushed a commit to wwwyyy/prebid-server that referenced this pull request Dec 20, 2021
* 'master' of https://github.com/wwwyyy/prebid-server: (23 commits)
  Add GPID Reserved Bidder Name (prebid#2107)
  Marsmedia adapter - param zoneId can get string and int (prebid#2105)
  Algorix: add Server Region Support (prebid#2096)
  New Adapter: Bizzclick (prebid#2056)
  Collect Prometheus Go process metrics (prebid#2101)
  Added channel support (prebid#2037)
  Rubicon: update fpd fields resolving (prebid#2091)
  Beachfront - Currency conversion (prebid#2078)
  New Adapter: Groupm (Alias Of PubMatic) (prebid#2042)
  Adform adapter lacked gross/net parameter support (prebid#2084)
  add iframe sync for openx (prebid#2094)
  changes to the correct user sync url (prebid#2092)
  Smaato: Add instl to tests (prebid#2089)
  Correct MakeRequests() output assertion in adapter JSON tests (prebid#2087)
  Adview: adapter currency fix. (prebid#2060)
  New Adapter: Coinzilla (prebid#2074)
  Syncer Level ExternalURL Override (prebid#2072)
  33Across: Enable Support for SRA requests (prebid#2079)
  Currency conversion on adapter JSON tests (prebid#2071)
  New Adapter: VideoByte (prebid#2058)
  ...
jorgeluisrocha pushed a commit to jwplayer/prebid-server that referenced this pull request Sep 28, 2022
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
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

Successfully merging this pull request may close these issues.

5 participants