Skip to content

Commit 410a5b2

Browse files
PeterAdams-AMordil
authored andcommitted
Change the scan test to accept up to 8 odd keys
This attempts to fix #23
1 parent 9958e2d commit 410a5b2

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

Tests/RediStackIntegrationTests/Commands/KeyCommandsTests.swift

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,30 @@ final class KeyCommandsTests: RediStackIntegrationTestCase {
122122
XCTFail("Expected '.noExpiry' but lifetime was \(hasNoExpire)")
123123
}
124124
}
125-
126-
// TODO: #23 -- Rework Scan Unit Test
127-
// This is extremely flakey, and causes non-deterministic failures because of the assert on key counts
128-
// func test_scan() throws {
129-
// var dataset: [RedisKey] = .init(repeating: "", count: 10)
130-
// for index in 1...15 {
131-
// let key = RedisKey("key\(index)\(index % 2 == 0 ? "_even" : "_odd")")
132-
// dataset.append(key)
133-
// _ = try connection.set(key, to: "\(index)").wait()
134-
// }
135-
//
136-
// var (cursor, keys) = try connection.scanKeys(count: 5).wait()
137-
// XCTAssertGreaterThanOrEqual(cursor, 0)
138-
// XCTAssertGreaterThanOrEqual(keys.count, 5)
139-
//
140-
// (_, keys) = try connection.scanKeys(startingFrom: cursor, count: 8).wait()
141-
// XCTAssertGreaterThanOrEqual(keys.count, 8)
142-
//
143-
// (cursor, keys) = try connection.scanKeys(matching: "*_odd").wait()
144-
// XCTAssertGreaterThanOrEqual(cursor, 0)
145-
// XCTAssertGreaterThanOrEqual(keys.count, 1)
146-
// XCTAssertLessThanOrEqual(keys.count, 7)
147-
//
148-
// (cursor, keys) = try connection.scanKeys(matching: "*_even*").wait()
149-
// XCTAssertGreaterThanOrEqual(cursor, 0)
150-
// XCTAssertGreaterThanOrEqual(keys.count, 1)
151-
// XCTAssertLessThanOrEqual(keys.count, 7)
152-
// }
125+
126+
func test_scan() throws {
127+
var dataset: [RedisKey] = .init(repeating: "", count: 10)
128+
for index in 1...15 {
129+
let key = RedisKey("key\(index)\(index % 2 == 0 ? "_even" : "_odd")")
130+
dataset.append(key)
131+
_ = try connection.set(key, to: "\(index)").wait()
132+
}
133+
134+
var (cursor, keys) = try connection.scanKeys(count: 5).wait()
135+
XCTAssertGreaterThanOrEqual(cursor, 0)
136+
XCTAssertGreaterThanOrEqual(keys.count, 5)
137+
138+
(_, keys) = try connection.scanKeys(startingFrom: cursor, count: 8).wait()
139+
XCTAssertGreaterThanOrEqual(keys.count, 8)
140+
141+
(cursor, keys) = try connection.scanKeys(matching: "*_odd").wait()
142+
XCTAssertGreaterThanOrEqual(cursor, 0)
143+
XCTAssertGreaterThanOrEqual(keys.count, 1)
144+
XCTAssertLessThanOrEqual(keys.count, 8)
145+
146+
(cursor, keys) = try connection.scanKeys(matching: "*_even*").wait()
147+
XCTAssertGreaterThanOrEqual(cursor, 0)
148+
XCTAssertGreaterThanOrEqual(keys.count, 1)
149+
XCTAssertLessThanOrEqual(keys.count, 7)
150+
}
153151
}

0 commit comments

Comments
 (0)