From b7b531f1c5bd146fe9580da83ff4f4bbe6fe9be9 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Mon, 5 Dec 2022 18:17:08 +0900 Subject: [PATCH] Uncomment test which was blocked on extensions not being picked up (#31) --- fdbserver/swift/tests/swift_test_task.swift | 102 ++++++++++---------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/fdbserver/swift/tests/swift_test_task.swift b/fdbserver/swift/tests/swift_test_task.swift index 2396c329723..a0526f4a65b 100644 --- a/fdbserver/swift/tests/swift_test_task.swift +++ b/fdbserver/swift/tests/swift_test_task.swift @@ -33,58 +33,56 @@ struct TaskTests: SimpleSwiftTestSuite { _ = try await voidF.waitValue } - // FIXME(swift): Somehow the waitValue is broken on FutureCInt: https://github.com/FoundationDB/foundationdb-swift/pull/31 -// TestCase("await \(FutureCInt.self)") { -// let p = PromiseCInt() -// var intF: FutureCInt = p.__getFutureUnsafe() -// -// var value: CInt = 42 -// p.send(&value) -// let got = try await intF.waitValue -// precondition(got == value, "\(got) did not equal \(value)") -// } - - // FIXME(swift): Somehow the waitValue is broken on FutureCInt: https://github.com/FoundationDB/foundationdb-swift/pull/31 -// TestCase("more Flow task await tests") { -// let p: PromiseCInt = PromiseCInt() -// var f: FutureCInt = p.__getFutureUnsafe() // FIXME(swift): getFuture: C++ method 'getFuture' that returns unsafe projection of type 'Future' not imported -// // TODO(swift): we perhaps should add a note that __getFutureUnsafe is available? -// -// pprint("got PromiseCInt") // FIXME(swift/c++): printing the promise crashes! -// precondition(!f.isReady(), "Future should not be ready yet") -// -// var num = 1111 -// pprint("send \(num)") // FIXME: printing the promise crashes! -// p.send(&num) // FIXME: rdar://99583467 ([C++ interop][fdb] Support xvalues, so we can use Future.send(U&& value)) -// pprint("without wait, f.get(): \(f.__getUnsafe().pointee)") -// -// pprint("wait...") -// let value: CInt = try await f.waitValue -// assertOnNet2EventLoop() // hopped back to the right executor, yay -// precondition(f.isReady(), "Future should be ready by now") -// -// pprint("await value = \(value)") -// precondition((value ?? -1) == num, "Value obtained from await did not match \(num), was: \(String(describing: value))!") -// -// pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2 --------------------") -// let p2 = PromiseCInt() -// var f2: FutureCInt = p2.__getFutureUnsafe() // FIXME: Make these not unsafe... -// let num2 = 2222 -// Task { [num2] in -// assertOnNet2EventLoop() -// -// pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2: send \(num2)") -// var workaroundVar = num2 // FIXME workaround since we need inout xvalue for the C++ send() -// p2.send(&workaroundVar) -// } -// pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2: waiting...") -// let got2: CInt? = try? await f2.waitValue -// pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2, got: \(String(describing: got2))") -// precondition(got2! == num2, "Value obtained from send after await did not match \(num2), was: \(String(describing: got2))!") -// -// // assert that we hopped back and are again on the Net2 event loop thread: -// assertOnNet2EventLoop() -// } + TestCase("await \(FutureCInt.self)") { + let p = PromiseCInt() + var intF: FutureCInt = p.__getFutureUnsafe() + + var value: CInt = 42 + p.send(&value) + let got = try await intF.waitValue + precondition(got == value, "\(got) did not equal \(value)") + } + + TestCase("more Flow task await tests") { + let p: PromiseCInt = PromiseCInt() + var f: FutureCInt = p.__getFutureUnsafe() // FIXME(swift): getFuture: C++ method 'getFuture' that returns unsafe projection of type 'Future' not imported + // TODO(swift): we perhaps should add a note that __getFutureUnsafe is available? + + pprint("got PromiseCInt") // FIXME(swift/c++): printing the promise crashes! + precondition(!f.isReady(), "Future should not be ready yet") + + var num = 1111 + pprint("send \(num)") // FIXME: printing the promise crashes! + p.send(&num) // FIXME: rdar://99583467 ([C++ interop][fdb] Support xvalues, so we can use Future.send(U&& value)) + pprint("without wait, f.get(): \(f.__getUnsafe().pointee)") + + pprint("wait...") + let value: CInt = try await f.waitValue + assertOnNet2EventLoop() // hopped back to the right executor, yay + precondition(f.isReady(), "Future should be ready by now") + + pprint("await value = \(value)") + precondition((value) == num, "Value obtained from await did not match \(num), was: \(String(describing: value))!") + + pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2 --------------------") + let p2 = PromiseCInt() + var f2: FutureCInt = p2.__getFutureUnsafe() // FIXME: Make these not unsafe... + let num2 = 2222 + Task { [num2] in + assertOnNet2EventLoop() + + pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2: send \(num2)") + var workaroundVar = num2 // FIXME workaround since we need inout xvalue for the C++ send() + p2.send(&workaroundVar) + } + pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2: waiting...") + let got2: CInt? = try? await f2.waitValue + pprint("[swift][tid:\(_tid())][\(#fileID):\(#line)](\(#function)) future 2, got: \(String(describing: got2))") + precondition(got2! == num2, "Value obtained from send after await did not match \(num2), was: \(String(describing: got2))!") + + // assert that we hopped back and are again on the Net2 event loop thread: + assertOnNet2EventLoop() + } TestCase("Flow task priorities in Task.priority") { await Task { assertOnNet2EventLoop() }.value