-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix ProvidersTest#network_attributes()
test TODO
#24
Fix ProvidersTest#network_attributes()
test TODO
#24
Conversation
All contributors have signed the CLA ✍️ ✅ |
- remove @ignore annotation - refactor ClientAttributes, DeviceAttributes and NetworkAttributes tests out of ProvidersTest and into their respective test classes - add more coverage to ClientAttributes, DeviceAttributes and NetworkAttributes - bump robolectric dependency version to 4.13
75b1f07
to
ac6305e
Compare
I have read the CLA Document and I hereby sign the CLA |
Thanks @pablo-guardiola ! I'll do a quick pass and take a closer look tomorrow |
} | ||
|
||
@Test | ||
@Ignore("Robolectric throwing ClassNotFoundException: android.telephony.TelephonyCallback") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was the actual fix of the TODO/failure? Was it just bumping Robolectric to 4.13?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. That issue was fixed in robolectric/robolectric#7786 and released as part of Robolectric 4.10
- it seems that the test was marked as ignored at some point and never revisited ¯\_(ツ)_/¯
That being said, I bumped to the latest available to avoid ClientAttributesTest#package_info_android_tiramisu()
's issue Skip package_info_android_tiramisu because Robolectric doesn't support legacy resources mode after P
(which gets fixed using Robolectric 4.11+).
@@ -19,7 +19,7 @@ mockitoCore = "4.9.0" | |||
mockitoKotlin = "2.2.0" | |||
mockitoKotlinVersion = "4.1.0" | |||
okhttp = "4.12.0" | |||
robolectric = "4.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until we finish the migration from bazel to gradle the integration (robolectric) tests are mostly run via CI using bazel, which means you might need to also bump
"org.robolectric:robolectric:4.11", |
As you can tell the versions were already out of sync :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! I tested both Bazel (./bazelw test //platform/jvm/...
) and Gradle locally. I was lucky that Robolectric's Bazel version was set to 4.11
and everything was passing 😅 (refs. #24 (comment)). Will bump Bazel dependency version to 4.13
to have them in sync 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will bump Bazel dependency version to 4.13 to have them in sync 👍
Done 👉 b3ac74c
There might be a bug in our CI checks where we didn't trigger the android jobs cause we didn't detect any "meaningful" android files had changed, will need to take a closer look, or @pablo-guardiola if you're curious this is the check that is managing the CI triggers
|
Great catch @murki 👍
capture-sdk/ci/files_changed.sh Line 10 in a5e8d0f
Another great point you brought was that the script is currently implemented in "fail-open" mode rather than "fail-closed". That should be fixed as well to report red if something fails - currently it feels that everything worked as the checks passed. Will try to take a stab at these and report back here. |
Thanks @pablo-guardiola, yeah ideally we should make the fixes on this same PR so we can progressively test that they work. Re: "fail-closed":
if git rev-parse --abbrev-ref HEAD | grep -q ^main$; then
exit 0
fi
git diff --name-only "origin/$GITHUB_BASE_REF" | grep -E "$1" Re: external contributions:
set -euo pipefail
# Fetch the base branch from the original repository using its URL
git fetch "https://github.com/${GITHUB_REPOSITORY}.git" "${GITHUB_BASE_REF}"
# Check if the current branch is `main`, exit if it is
if git rev-parse --abbrev-ref HEAD | grep -q ^main$; then
exit 0
fi
# Check if relevant files have changed between the current branch and the base branch
git diff --name-only "FETCH_HEAD" | grep -E "$1" |
118caa5
to
d2fc882
Compare
https://github.com/bitdriftlabs/capture-sdk/actions/runs/10741877498/job/29793722002?pr=24
Looking |
I think I know what's going on. It seems that we're not fetching the remote base branch. Apparently, even though |
79e8341
to
f43625b
Compare
@murki got some time to implement the "fail-closed" mode properly and now should be working fine (including external contributions / forks) 🚀 Please, give it a try when you have a chance 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pablo-guardiola for your contributions and your steadfastness towards improving our CI along the way. Changes look good to me
As I continue my journey exploring
capture-sdk
's repo / learning how bitdrift's Capture SDK works, I noticed thatProvidersTest
had an easyTODO
that I could tackle, so this is a quick fix that addresses that tech debt. While working on that, I also went ahead and refactoredProvidersTest
and added some more coverage toClientAttributes
,DeviceAttributes
andNetworkAttributes
.Fixes
ProvidersTest#network_attributes()
testTODO
:@Ignore
annotationClientAttributes
,DeviceAttributes
andNetworkAttributes
tests out ofProvidersTest
and into their respective test classesClientAttributes
,DeviceAttributes
andNetworkAttributes
4.13
Refactored the tests to have only 1 assertion per test and one test per scenario 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=57
Basically, if one of them fails you'll know at a glance what in the code might have caused that failure and in which part (class, method, etc.).
The problems of having multiple assertions are:
I rarely write tests with multiple assertions (at least I try 😅), only if they're tearing apart the result object to verify everything e.g. if there's no
equals
(which is another problem although could happen if it's coming from a 3rd party library object) or if the assertions are atomic to the object.This is a technique that I learnt from the book Working Effectively With Unit Tests. I really like the techniques described on it in favor of DAMP (Descriptive And Maintainable Procedures). Mainly because they increase maintainability and readability of tests. Another great one (already followed in the project ❤️) is to structure the tests following the triple
A
-A
rrange /A
ct /A
ssert (I removed the explicit comments as IMO are unnecessary).BTW, I highly recommend you reading that book (if you haven't already). It's 🔝 💯