amplify-swift
amplify-swift copied to clipboard
DataStore observeQuery flaky test
Describe the bug
AWSDataStorePluginSubscribeBehaviorTests::testObserveQueryResetAfterDataStoreStop intermittently fails with
uncaught exception 'NSInternalInconsistencyException', reason: 'Must be called on the main thread' terminating with uncaught exception of type NSException.
The exception seems to be generating in ObserveQuerySubscription at line 57
Steps To Reproduce
Steps to reproduce the behavior:
1. Run `testObserveQueryResetAfterDataStoreStop` test cases repeatedly
Expected behavior
N/A
Amplify Framework Version
1.26.1
Amplify Categories
DataStore
Dependency manager
Swift PM
Swift version
5.6
CLI version
N/A
Xcode version
13.4.1
Relevant log output
No response
Is this a regression?
No
Regression additional context
No response
Device
N/A
iOS Version
N/A
Specific to simulators
N/A
Additional context
No response
Stack trace
* thread #9, queue = 'com.amazonaws.ObserveQuerySubscription.serialQueue', stop reason = signal SIGABRT
* frame #0: 0x000000010fd6300e libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x000000010fded1ff libsystem_pthread.dylib`pthread_kill + 263
frame #2: 0x000000010886025e libclang_rt.tsan_iossim_dynamic.dylib`wrap_pthread_kill + 302
frame #3: 0x000000010fae4b7c libsystem_c.dylib`abort + 120
frame #4: 0x000000010885f687 libclang_rt.tsan_iossim_dynamic.dylib`wrap_abort + 103
frame #5: 0x000000010ec0f858 libc++abi.dylib`abort_message + 231
frame #6: 0x000000010ec00cbf libc++abi.dylib`demangling_terminate_handler() + 262
frame #7: 0x000000010c4d1c0b libobjc.A.dylib`_objc_terminate() + 96
frame #8: 0x000000010ec0ec87 libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #9: 0x000000010ec0ec29 libc++abi.dylib`std::terminate() + 41
frame #10: 0x000000010c4d1bab libobjc.A.dylib`objc_terminate + 9
frame #11: 0x000000010f9368df libdispatch.dylib`_dispatch_client_callout + 28
frame #12: 0x000000010f93c60c libdispatch.dylib`_dispatch_lane_serial_drain + 707
frame #13: 0x000000010f93d044 libdispatch.dylib`_dispatch_lane_invoke + 388
frame #14: 0x000000010f9470c4 libdispatch.dylib`_dispatch_workloop_worker_thread + 626
frame #15: 0x000000010fde9fd0 libsystem_pthread.dylib`_pthread_wqthread + 326
frame #16: 0x000000010fde8f57 libsystem_pthread.dylib`start_wqthread + 15
* thread #1, queue = 'com.apple.main-thread'
frame #0: 0x0000000108848869 libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::Put(__sanitizer::StackTrace, bool*) + 281
frame #1: 0x000000010884873c libclang_rt.tsan_iossim_dynamic.dylib`__sanitizer::StackDepotPut(__sanitizer::StackTrace) + 28
frame #2: 0x000000010888c745 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::CurrentStackId(__tsan::ThreadState*, unsigned long) + 69
frame #3: 0x00000001088a1907 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::MetaMap::AllocBlock(__tsan::ThreadState*, unsigned long, unsigned long, unsigned long) + 167
frame #4: 0x0000000108885285 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::user_alloc_internal(__tsan::ThreadState*, unsigned long, unsigned long, unsigned long, bool) + 149
frame #5: 0x0000000108885b26 libclang_rt.tsan_iossim_dynamic.dylib`__tsan::user_alloc(__tsan::ThreadState*, unsigned long, unsigned long) + 22
frame #6: 0x00000001088833b8 libclang_rt.tsan_iossim_dynamic.dylib`wrap_malloc + 104
frame #7: 0x000000010ed95a0d libicucore.A.dylib`___lldb_unnamed_symbol1831$$libicucore.A.dylib + 1321
frame #8: 0x000000010ed32e21 libicucore.A.dylib`___lldb_unnamed_symbol1152$$libicucore.A.dylib + 136
frame #9: 0x000000010ed32d76 libicucore.A.dylib`ures_getAllItemsWithFallback + 276
frame #10: 0x000000010ec920a7 libicucore.A.dylib`icu::DateFormatSymbols::initializeData(icu::Locale const&, char const*, UErrorCode&, signed char) + 1355
frame #11: 0x000000010ed913f4 libicucore.A.dylib`icu::LocaleCacheKey<icu::SharedDateFormatSymbols>::createObject(void const*, UErrorCode&) const + 144
frame #12: 0x000000010ed22a81 libicucore.A.dylib`icu::UnifiedCache::_get(icu::CacheKeyBase const&, icu::SharedObject const*&, void const*, UErrorCode&) const + 105
frame #13: 0x000000010ed96f13 libicucore.A.dylib`___lldb_unnamed_symbol1838$$libicucore.A.dylib + 65
frame #14: 0x000000010ed91619 libicucore.A.dylib`___lldb_unnamed_symbol1820$$libicucore.A.dylib + 127
frame #15: 0x000000010ed914f7 libicucore.A.dylib`icu::DateFormatSymbols::createForLocale(icu::Locale const&, UErrorCode&) + 37
frame #16: 0x000000010ec8ece6 libicucore.A.dylib`icu::SimpleDateFormat::construct(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&) + 608
frame #17: 0x000000010ec8ea18 libicucore.A.dylib`icu::SimpleDateFormat::SimpleDateFormat(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&, UErrorCode&) + 212
frame #18: 0x000000010ec8e8c9 libicucore.A.dylib`icu::DateFormat::create(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale const&) + 159
frame #19: 0x000000010ec8e723 libicucore.A.dylib`udat_open + 375
frame #20: 0x000000010c6700d3 CoreFoundation`__cficu_udat_open + 83
frame #21: 0x000000010c562e59 CoreFoundation`__ResetUDateFormat + 457
frame #22: 0x000000010c56285b CoreFoundation`__CreateCFDateFormatter + 331
frame #23: 0x000000010bf8a4ab Foundation`-[NSDateFormatter _regenerateFormatter] + 259
frame #24: 0x000000010bf8b112 Foundation`-[NSDateFormatter stringForObjectValue:] + 138
frame #25: 0x000000012c4c49e9 Amplify`TemporalSpec.iso8601FormattedString(format=full, timeZone=Foundation.TimeZone @ 0x0000000304376510, self=) at Temporal.swift:101:26
frame #26: 0x000000012c4c4b62 Amplify`TemporalSpec.iso8601String.getter(self=) at Temporal.swift:107:9
frame #27: 0x000000012c33b896 Amplify`protocol witness for TemporalSpec.iso8601String.getter in conformance Temporal.DateTime at <compiler-generated>:0
frame #28: 0x000000012c4c51ce Amplify`TemporalSpec<>.encode(encoder=0x00007b24000157b0, self=) at Temporal+Codable.swift:18:30
frame #29: 0x000000012c4c55b5 Amplify`protocol witness for Encodable.encode(to:) in conformance Temporal.DateTime at <compiler-generated>:0
frame #30: 0x00000001301b1307 libswiftCore.dylib`dispatch thunk of Swift.Encodable.encode(to: Swift.Encoder) throws -> () + 7
frame #31: 0x00000001306ff8e8 libswiftFoundation.dylib`Foundation.__JSONEncoder.box_(Swift.Encodable) throws -> Swift.Optional<__C.NSObject> + 4376
frame #32: 0x000000013070ca13 libswiftFoundation.dylib`Foundation._JSONKeyedEncodingContainer.encode<τ_0_0 where τ_1_0: Swift.Encodable>(_: τ_1_0, forKey: τ_0_0) throws -> () + 3811
frame #33: 0x00000001307111d5 libswiftFoundation.dylib`protocol witness for Swift.KeyedEncodingContainerProtocol.encode<τ_0_0 where τ_1_0: Swift.Encodable>(_: τ_1_0, forKey: τ_0_0.Key) throws -> () in conformance Foundation._JSONKeyedEncodingContainer<τ_0_0> : Swift.KeyedEncodingContainerProtocol in Foundation + 21
frame #34: 0x00000001300c8dd7 libswiftCore.dylib`Swift._KeyedEncodingContainerBox.encode<τ_0_0 where τ_1_0: Swift.Encodable>(_: τ_1_0, forKey: τ_0_0.Key) throws -> () + 39
frame #35: 0x000000013008711c libswiftCore.dylib`Swift.KeyedEncodingContainer.encode<τ_0_0 where τ_1_0: Swift.Encodable>(_: τ_1_0, forKey: τ_0_0) throws -> () + 76
frame #36: 0x000000012cbde889 AmplifyTestCommon`Post.encode(encoder=0x00007b24000157b0, self=AmplifyTestCommon.Post @ 0x00007b1c00021640) at <compiler-generated>:0
frame #37: 0x000000012cbe0646 AmplifyTestCommon`protocol witness for Encodable.encode(to:) in conformance Post at <compiler-generated>:0
frame #38: 0x00000001301b1307 libswiftCore.dylib`dispatch thunk of Swift.Encodable.encode(to: Swift.Encoder) throws -> () + 7
frame #39: 0x00000001306ff8e8 libswiftFoundation.dylib`Foundation.__JSONEncoder.box_(Swift.Encodable) throws -> Swift.Optional<__C.NSObject> + 4376
frame #40: 0x00000001306fe388 libswiftFoundation.dylib`Foundation.JSONEncoder.encode<τ_0_0 where τ_0_0: Swift.Encodable>(τ_0_0) throws -> Foundation.Data + 456
frame #41: 0x00000001307f05de libswiftFoundation.dylib`dispatch thunk of Foundation.JSONEncoder.encode<τ_0_0 where τ_0_0: Swift.Encodable>(τ_0_0) throws -> Foundation.Data + 14
* frame #42: 0x000000012c425e05 Amplify`Model.toJSON(encoder=nil, self=AmplifyTestCommon.Post @ 0x0000000304377960) at Model+Codable.swift:81:40
frame #43: 0x000000012c459324 Amplify`MutationEvent.init<M>(model=AmplifyTestCommon.Post @ 0x0000000304377960, modelSchema=Amplify.ModelSchema @ 0x0000000304377ee8, mutationType=create, version=nil, graphQLFilterJSON=nil) at MutationEvent.swift:49:30
frame #44: 0x000000012a9c99cc AWSDataStoreCategoryPluginTests`AWSMutationDatabaseAdapterTests.test_dropCandidate_localCreateCandidateDelete(self=0x00007b4800006480) at AWSMutationDatabaseAdapterTests.swift:114:31
frame #45: 0x000000012a9ca0a8 AWSDataStoreCategoryPluginTests`@objc AWSMutationDatabaseAdapterTests.test_dropCandidate_localCreateCandidateDelete() at <compiler-generated>:0
frame #46: 0x000000010c661dec CoreFoundation`__invoking___ + 140
frame #47: 0x000000010c65efd1 CoreFoundation`-[NSInvocation invoke] + 321
frame #48: 0x0000000120ab3588 XCTestCore`+[XCTFailableInvocation invokeErrorConventionInvocation:completion:] + 118
frame #49: 0x0000000120ab3510 XCTestCore`__90+[XCTFailableInvocation invokeInvocation:withTestMethodConvention:lastObservedErrorIssue:]_block_invoke + 23
frame #50: 0x0000000120ab31ef XCTestCore`__81+[XCTFailableInvocation invokeWithAsynchronousWait:lastObservedErrorIssue:block:]_block_invoke.13 + 71
frame #51: 0x0000000120a6fd83 XCTestCore`+[XCTSwiftErrorObservation observeErrorsInBlock:] + 68
frame #52: 0x0000000120ab3084 XCTestCore`+[XCTFailableInvocation invokeWithAsynchronousWait:lastObservedErrorIssue:block:] + 443
frame #53: 0x0000000120ab34c3 XCTestCore`+[XCTFailableInvocation invokeInvocation:withTestMethodConvention:lastObservedErrorIssue:] + 205
frame #54: 0x0000000120ab37ca XCTestCore`+[XCTFailableInvocation invokeInvocation:lastObservedErrorIssue:] + 64
frame #55: 0x0000000120aa02c1 XCTestCore`__24-[XCTestCase invokeTest]_block_invoke.287 + 112
frame #56: 0x0000000120a67f33 XCTestCore`-[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:] + 181
frame #57: 0x0000000120a9fe4e XCTestCore`-[XCTestCase invokeTest] + 899
frame #58: 0x0000000120aa16b8 XCTestCore`__26-[XCTestCase performTest:]_block_invoke.396 + 43
frame #59: 0x0000000120a67f33 XCTestCore`-[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:] + 181
frame #60: 0x0000000120aa1041 XCTestCore`__26-[XCTestCase performTest:]_block_invoke.375 + 516
frame #61: 0x0000000120a859b6 XCTestCore`+[XCTContext runInContextForTestCase:markAsReportingBase:block:] + 218
frame #62: 0x0000000120aa0c65 XCTestCore`-[XCTestCase performTest:] + 287
frame #63: 0x0000000120a55853 XCTestCore`-[XCTest runTest] + 57
frame #64: 0x0000000120a88d12 XCTestCore`-[XCTestSuite runTestBasedOnRepetitionPolicy:testRun:] + 151
frame #65: 0x0000000120a88b92 XCTestCore`__27-[XCTestSuite performTest:]_block_invoke + 243
frame #66: 0x0000000120a884a6 XCTestCore`__59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
frame #67: 0x0000000120a859b6 XCTestCore`+[XCTContext runInContextForTestCase:markAsReportingBase:block:] + 218
frame #68: 0x0000000120a8845d XCTestCore`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 159
frame #69: 0x0000000120a8874f XCTestCore`-[XCTestSuite performTest:] + 219
frame #70: 0x0000000120a55853 XCTestCore`-[XCTest runTest] + 57
frame #71: 0x0000000120a88d12 XCTestCore`-[XCTestSuite runTestBasedOnRepetitionPolicy:testRun:] + 151
frame #72: 0x0000000120a88b92 XCTestCore`__27-[XCTestSuite performTest:]_block_invoke + 243
frame #73: 0x0000000120a884a6 XCTestCore`__59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
frame #74: 0x0000000120a859b6 XCTestCore`+[XCTContext runInContextForTestCase:markAsReportingBase:block:] + 218
frame #75: 0x0000000120a8845d XCTestCore`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 159
frame #76: 0x0000000120a8874f XCTestCore`-[XCTestSuite performTest:] + 219
frame #77: 0x0000000120a55853 XCTestCore`-[XCTest runTest] + 57
frame #78: 0x0000000120a88d12 XCTestCore`-[XCTestSuite runTestBasedOnRepetitionPolicy:testRun:] + 151
frame #79: 0x0000000120a88b92 XCTestCore`__27-[XCTestSuite performTest:]_block_invoke + 243
frame #80: 0x0000000120a884a6 XCTestCore`__59-[XCTestSuite _performProtectedSectionForTest:testSection:]_block_invoke + 24
frame #81: 0x0000000120a859b6 XCTestCore`+[XCTContext runInContextForTestCase:markAsReportingBase:block:] + 218
frame #82: 0x0000000120a8845d XCTestCore`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 159
frame #83: 0x0000000120a8874f XCTestCore`-[XCTestSuite performTest:] + 219
frame #84: 0x0000000120a55853 XCTestCore`-[XCTest runTest] + 57
frame #85: 0x0000000120a57371 XCTestCore`__89-[XCTTestRunSession executeTestsWithIdentifiers:skippingTestsWithIdentifiers:completion:]_block_invoke + 115
frame #86: 0x0000000120a859b6 XCTestCore`+[XCTContext runInContextForTestCase:markAsReportingBase:block:] + 218
frame #87: 0x0000000120a57259 XCTestCore`-[XCTTestRunSession executeTestsWithIdentifiers:skippingTestsWithIdentifiers:completion:] + 271
frame #88: 0x0000000120ac10da XCTestCore`__72-[XCTExecutionWorker enqueueTestIdentifiersToRun:testIdentifiersToSkip:]_block_invoke_2 + 119
frame #89: 0x0000000120ac1200 XCTestCore`-[XCTExecutionWorker runWithError:] + 112
frame #90: 0x0000000120a82df9 XCTestCore`__25-[XCTestDriver _runTests]_block_invoke.322 + 61
frame #91: 0x0000000120a604a1 XCTestCore`-[XCTestObservationCenter _observeTestExecutionForBlock:] + 307
frame #92: 0x0000000120a82a2c XCTestCore`-[XCTestDriver _runTests] + 1457
frame #93: 0x0000000120a55e39 XCTestCore`_XCTestMain + 125
frame #94: 0x00000001000c44c4 xctest`main + 211
frame #95: 0x000000020020b51e dyld`start + 462
This code path is only executed in v1 of DataStore. main (V2) has removed the layer that creates the published from the operation
Added to the main issue to track this - https://github.com/aws-amplify/amplify-swift/issues/2336