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

Revert "Make it commit order and receive order are same in concurrent" #102

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions Sources/VergeCore/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,13 @@ open class Storage<Value>: ReadonlyStorage<Value> {

lock()
do {

let r = try update(&nonatomicValue)
let notifyValue = nonatomicValue

unlock()
// TODO: cause cracking the order of event
if notificationFilter(notifyValue) {
// notify the event with locking
// it may cause dead-lock in somecase
notifyDidUpdate(value: notifyValue)
}

unlock()
return r
} catch {
unlock()
Expand Down
10 changes: 6 additions & 4 deletions Tests/VergeStoreTests/VergeStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,15 @@ final class VergeStoreTests: XCTestCase {
}

func testOrderOfEvents() {


// Currently, it's collapsed because Storage emits event without locking.

let store = VergeStore.Store<DemoState, Never>(initialState: .init(), logger: nil)

let exp = expectation(description: "")
let counter = expectation(description: "update count")
counter.assertForOverFulfill = true
counter.expectedFulfillmentCount = 10001
counter.expectedFulfillmentCount = 1001

let results: VergeConcurrency.Atomic<[Int]> = .init([])

Expand All @@ -323,7 +325,7 @@ final class VergeStoreTests: XCTestCase {
}

DispatchQueue.global().async {
DispatchQueue.concurrentPerform(iterations: 10000) { (i) in
DispatchQueue.concurrentPerform(iterations: 1000) { (i) in
store.commit {
$0.count += 1
}
Expand All @@ -333,7 +335,7 @@ final class VergeStoreTests: XCTestCase {
}

wait(for: [exp, counter], timeout: 10)
XCTAssertEqual(Array((0...10000).map { $0 }), results.value)
XCTAssertEqual(Array((0...1000).map { $0 }), results.value)
withExtendedLifetime(sub) {}
}

Expand Down
3 changes: 3 additions & 0 deletions Verge.xcodeproj/xcshareddata/xcschemes/LightAll.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
<Test
Identifier = "VergeStoreTests/testDeadlock()">
</Test>
<Test
Identifier = "VergeStoreTests/testOrderOfEvents()">
</Test>
</SkippedTests>
</TestableReference>
<TestableReference
Expand Down