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

Add more GC tests to reflect current server modifications #130

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Tests/Integration/GCTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,75 @@ class GCTests: XCTestCase {
len = await doc.getGarbageLengthFromClone()
XCTAssertEqual(len, 6)
}

func test_can_purges_removed_elements_after_peers_can_not_access_them() async throws {
let options = ClientOptions()
let docKey = "\(self.description)-\(Date().description)".toDocKey

let doc1 = Document(key: docKey)
let doc2 = Document(key: docKey)

let client1 = Client(rpcAddress: rpcAddress, options: options)
let client2 = Client(rpcAddress: rpcAddress, options: options)

try await client1.activate()
try await client2.activate()

try await client1.attach(doc1, [:], false)

try await doc1.update { root, _ in
root.point = ["x": Int64(0), "y": Int64(0)]
}

try await doc1.update { root, _ in
(root.point as? JSONObject)?.x = Int64(1)
}

var len = await doc1.getGarbageLength()
XCTAssertEqual(len, 1)

try await client1.sync()

try await client2.attach(doc2, [:], false)

len = await doc2.getGarbageLength()
XCTAssertEqual(len, 1)

try await doc2.update { root, _ in
(root.point as? JSONObject)?.x = Int64(2)
}

len = await doc2.getGarbageLength()
XCTAssertEqual(len, 2)

try await doc1.update { root, _ in
root.point = ["x": Int64(3), "y": Int64(3)]
}

len = await doc1.getGarbageLength()
XCTAssertEqual(len, 4)
try await client1.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 4)

try await client1.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 4)

try await client2.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 4)
try await client1.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 5)
try await client2.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 5)
try await client1.sync()
len = await doc1.getGarbageLength()
XCTAssertEqual(len, 0)

try await client1.deactivate()
try await client2.deactivate()
}
}