Skip to content

Commit

Permalink
Lock local changes to assert transactions (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
humdrum authored Jun 18, 2024
1 parent ae2dc99 commit f8b9233
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
33 changes: 33 additions & 0 deletions Tests/Integration/ClientIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,37 @@ final class ClientIntegrationTests: XCTestCase {
try await c1.deactivate()
try await c2.deactivate()
}

func test_duplicated_local_changes_not_sent_to_server() async throws {
try await withTwoClientsAndDocuments(self.description, detachDocuments: false) { c1, d1, c2, d2 in
try await d1.update { root, _ in
root.t = JSONTree(initialRoot:
JSONTreeElementNode(type: "doc",
children: [
JSONTreeElementNode(type: "p", children: [JSONTreeTextNode(value: "12")]),
JSONTreeElementNode(type: "p", children: [JSONTreeTextNode(value: "34")])
])
)
}

try await c1.sync()
try await c1.sync()
try await c1.sync()
try await c1.detach(d1)

try await Task.sleep(nanoseconds: 3_000_000_000)

try await c2.sync()

let d1XML = await(d1.getRoot().t as? JSONTree)?.toXML()
let d2XML = await(d2.getRoot().t as? JSONTree)?.toXML()
XCTAssertEqual(d1XML, /* html */ "<doc><p>12</p><p>34</p></doc>")
XCTAssertEqual(d2XML, /* html */ "<doc><p>12</p><p>34</p></doc>")

try await c2.detach(d2)

try await c1.deactivate()
try await c2.deactivate()
}
}
}
12 changes: 7 additions & 5 deletions Tests/Integration/IntegrationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import XCTest
@testable import Yorkie

func withTwoClientsAndDocuments(_ title: String, _ callback: (Client, Document, Client, Document) async throws -> Void) async throws {
func withTwoClientsAndDocuments(_ title: String, detachDocuments: Bool = true, _ callback: (Client, Document, Client, Document) async throws -> Void) async throws {
let rpcAddress = "http://localhost:8080"

let docKey = "\(Date().description)-\(title)".toDocKey
Expand All @@ -36,11 +36,13 @@ func withTwoClientsAndDocuments(_ title: String, _ callback: (Client, Document,

try await callback(c1, d1, c2, d2)

try await c1.detach(d1)
try await c2.detach(d2)
if detachDocuments {
try await c1.detach(d1)
try await c2.detach(d2)

try await c1.deactivate()
try await c2.deactivate()
try await c1.deactivate()
try await c2.deactivate()
}
}

protocol OperationInfoForDebug {}
Expand Down

0 comments on commit f8b9233

Please sign in to comment.