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

[Objc] add ios libuv timer test #28570

Merged
merged 6 commits into from
Mar 16, 2022
Merged

Conversation

HannahShiSFB
Copy link
Collaborator

@HannahShiSFB HannahShiSFB commented Jan 14, 2022

libuv test source is build as libuv_test library and selected test cases will be ran from objective C code.

Currently tests are manually selected and put into objective C tests, in long term we may consider add some script to extract the libuv test cases and report if libuv added or removed test cases.

use the following command to run test:
./tools/bazel run //src/objective-c/tests/ThirdPartyTests/Libuv:LibuvTest

@drfloob
@dennycd

@dennycd
Copy link
Contributor

dennycd commented Jan 14, 2022

thanks Hannah, it is great to see that we can now import and reuse libuv test suite ; ) Can you update the PR description with a few summary of

  • how iOS is reusing libuv test source
  • for ongoing maintenance (e.g. we bumped libuv version), what changes we need to make

static int connect_port = -1;

-static int getsocknamecount = 0;
+static int getsocknamecount_tcp = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we need to separate the callback counting here (thus this patch), is there a difference on iOS test context that makes the vanilla libuv test invalid here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The static variable was used by multi test cases, it was OK since other languages use fork and count separately. But in iOS test, we have to run all tests in the same process, so we need separate variables to count separately.

@implementation LibuvTimerTests

- (void)testTimerAll {
for (task_entry_t* task = TASKS; task->main; task++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we will need a way to obtain the test result signals from these test by calling into XCTest's assertion methods (https://developer.apple.com/documentation/xctest?language=objc). Currently if we just run these it will always be reported as success (unless it crashed), thanks !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The ASSERT works. If a test case fails at any assert, the whole test will crash. It'll be reported as success, only when all assert in all test cases passed.

@HannahShiSFB
Copy link
Collaborator Author

thanks Hannah, it is great to see that we can now import and reuse libuv test suite ; ) Can you update the PR description with a few summary of

  • how iOS is reusing libuv test source
  • for ongoing maintenance (e.g. we bumped libuv version), what changes we need to make

added

@dennycd
Copy link
Contributor

dennycd commented Feb 11, 2022

thanks for the update, all test looks good

Copy link
Member

@drfloob drfloob left a comment

Choose a reason for hiding this comment

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

Sorry I didn't see this sooner. I'm glad to see you found a way to run libuv tests on iOS!

@@ -0,0 +1,56 @@
diff --git a/test/test-timer.c b/test/test-timer.c
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a general change to the libuv test code, nothing gRPC-specific. I don't see why we'd want to maintain patches for general improvements that they'd likely accept and maintain upstream. Patches are a maintenance burden best avoided, if possible. For example, if it does not apply cleanly onto the next libuv version, upgrading the libuv dependency now means we'd have to port a patch before we could do the upgrade.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will send a PR to libuv after we finished adding other tests and collected all the patches needed.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Please collect the patches separately, and remove them from this PR. If it was a patch for something that we absolutely need for libuv to function on iOS, the extra burden is justifiable. But this is not essential, and again, every patch we have to maintain adds a real maintenance burden for library upgrades.

Copy link
Contributor

Choose a reason for hiding this comment

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

Chatted w/ Hannah offline, we have a solution to run iOS test without patching libuv via ios_ui_test. This allows us to re-launch the app per test case via XCUIApplication.launch if needed in order to simulate the same fork run behavior as other platform.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unfortunately, re-launch ios ui app didn't work, it might because that it only restarts the ios ui toolkit part, not the entire process.
PS: ios ui test also runs super slow due to boot up the simulator.

If we cannot add patch in our build system, could we try upstream it to libuv and wait for them to merge first?

Another alternative maybe split LibuvTest​ target into smaller ones, though it'll make the project a bit messy.

Error log with ios ui test:

Assertion failed in external/com_github_libuv_libuv/test/test-timer.c on line 152: once_cb_called == 1
...
Failing tests:
Runner:
-[LibuvTimerTests testTimerStartTwice]

** TEST EXECUTE FAILED **

Copy link
Contributor

Choose a reason for hiding this comment

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

discussed offline, we will add back timer_start_twice test in a follow up PR pending the process relaunch fix

ASSERT(r == 0);

- ASSERT(once_cb_called == 1);
+ ASSERT(twice_cb_called == 1);
Copy link
Member

Choose a reason for hiding this comment

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

This change could be a bit misleading. The purpose of this test is that once_cb is called exactly once, even when started twice. Calling it twice_cb maybe implies that it's somehow different from once_cb, which it should not be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It’s for test case timer_start_twice, which is the named similar to other xx_cb variables. Can we keep it for now and let the libuv team decide when I send them the PR?

deps = [
":libuv"
],
linkopts = select({
Copy link
Member

Choose a reason for hiding this comment

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

The same copts would be needed here as well, I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

comment addressed

"//conditions:default": [],
}),
visibility = [
"//visibility:public",
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be publicly visible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried with "//src/objective-c/tests/ThirdPartyTests/Libuv:LibuvTestsLib” but didn’t work, any suggestions?

@dennycd
Copy link
Contributor

dennycd commented Feb 25, 2022

Thanks for the update @HannahShiSFB . Let's remove libuv patch and split the PR with bazel only changes here. We can add iOS test setup in a follow up. Cheers

@HannahShiSFB
Copy link
Collaborator Author

Thanks for the update @HannahShiSFB . Let's remove libuv patch and split the PR with bazel only changes here. We can add iOS test setup in a follow up. Cheers

libuv patch removed.

@dennycd dennycd merged commit 842ed8d into grpc:master Mar 16, 2022
@copybara-service copybara-service bot added the imported Specifies if the PR has been imported to the internal repository label Mar 16, 2022
anicr7 pushed a commit to anicr7/grpc that referenced this pull request Apr 1, 2022
* use libuv in third party

* add ios libuv timer test

* name changed correspondingly

* format code

* address comment

* remove libuv patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bloat/none imported Specifies if the PR has been imported to the internal repository lang/ObjC perf-change/none platform/iOS release notes: no Indicates if PR should not be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants