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

(#1332) Fix crashes in test case PushTests.test__008__LocalDevice__has_a_device_method_that_returns_a_LocalDevice (4f837671-6233-41f1-94e8-01174d1da7b8) #1392

Conversation

lawrence-forooghian
Copy link
Collaborator

What does this do?

Introduces various concurrency-related fixes related to the local device. Together, I believe these fix various crashes that we've observed in the test mentioned in the title (#1332). See commit messages for more details.

How do I know it's fixed the test?

These are the results of the tests running continuously with these fixes applied. At time of writing, there are 97 test runs with no failures in this test, but I'll keep it running for a while more before merging.

We currently read / write the variable that stores the shared
ARTLocalDevice variable from the internal queue of the ARTRest instance
through which the device is being accessed. But, since each ARTRest
instance has its own queue, this means that access to this variable
isn’t currently synchronised between multiple ARTRest instances.

So, here we do that.

This also allows us to remove our usage of dispatch_once. This is a good
thing, because we were using it incorrectly before. From an Apple
engineer on https://stackoverflow.com/a/19845164:

> The implementation of dispatch_once() requires that the
> dispatch_once_t is zero, and has never been non-zero.

That is, you can’t reset a dispatch_once_t variable and expect
dispatch_once to still work with it, which is what we were doing.
This doesn’t change anything, it just explains the current behaviour of
the code.

ARTLocalDeviceStorage already conforms to these requirements, since it
uses the (already thread-safe) user defaults / keychain. However,
MockDeviceStorage does need some synchronisation. I’ll do that next.
As promised in e0ff029.

Together with de281bd and fbd5645, I believe this closes #1332 (various
crashes in
PushTests.test__008__LocalDevice__has_a_device_method_that_returns_a_LocalDevice,
which seemed to be related to threading).

Test case:
https://test-observability.herokuapp.com/repos/ably/ably-cocoa/test_cases/4f837671-6233-41f1-94e8-01174d1da7b8
Source/ARTRest.m Show resolved Hide resolved
Source/ARTRest.m Show resolved Hide resolved
@lawrence-forooghian lawrence-forooghian merged commit 2d48c34 into main May 9, 2022
@lawrence-forooghian lawrence-forooghian deleted the 1332-fix-test-case-4f837671-6233-41f1-94e8-01174d1da7b8 branch May 9, 2022 01:22
maratal pushed a commit that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants