Skip to content

Commit 3fb6e2f

Browse files
committed
temp make notify/listen internal
1 parent c057de6 commit 3fb6e2f

File tree

2 files changed

+85
-89
lines changed

2 files changed

+85
-89
lines changed

Sources/PostgreSQL/Connection/PostgreSQLConnection+NotifyAndListen.swift

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import Async
44
extension PostgreSQLConnection {
55
/// Note: after calling `listen'` on a connection, it can no longer handle other database operations. Do not try to send other SQL commands through this connection afterwards.
66
/// IAlso, notifications will only be sent for as long as this connection remains open; you are responsible for opening a new connection to listen on when this one closes.
7-
public func listen(
8-
_ channelName: String,
9-
handler: @escaping (String) throws -> ()
10-
) throws -> Future<Void> {
7+
internal func listen(_ channelName: String, handler: @escaping (String) throws -> ()) throws -> Future<Void> {
118
closeHandlers.append({ conn in
129
let query = PostgreSQLQuery(query: "UNLISTEN \"\(channelName)\";")
1310
return conn.send([.query(query)], onResponse: { _ in })
@@ -28,13 +25,12 @@ extension PostgreSQLConnection {
2825
})
2926
}
3027

31-
public func notify(
32-
_ channelName: String, message: String) throws -> Future<Void> {
28+
internal func notify(_ channelName: String, message: String) throws -> Future<Void> {
3329
let query = PostgreSQLQuery(query: "NOTIFY \"\(channelName)\", '\(message)';")
3430
return send([.query(query)]).map(to: Void.self, { _ in })
3531
}
3632

37-
public func unlisten(_ channelName: String, unlistenHandler: (() -> Void)? = nil) throws -> Future<Void> {
33+
internal func unlisten(_ channelName: String, unlistenHandler: (() -> Void)? = nil) throws -> Future<Void> {
3834
notificationHandlers.removeValue(forKey: channelName)
3935
let query = PostgreSQLQuery(query: "UNLISTEN \"\(channelName)\";")
4036
return send([.query(query)], onResponse: { _ in unlistenHandler?() })

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

+82-82
Original file line numberDiff line numberDiff line change
@@ -343,85 +343,85 @@ class PostgreSQLConnectionTests: XCTestCase {
343343
_ = try categories.wait()
344344
}
345345

346-
func testNotifyAndListen() throws {
347-
let completionHandlerExpectation1 = expectation(description: "first completion handler called")
348-
let completionHandlerExpectation2 = expectation(description: "final completion handler called")
349-
let notifyConn = try PostgreSQLConnection.makeTest()
350-
let listenConn = try PostgreSQLConnection.makeTest()
351-
let channelName = "Fooze"
352-
let messageText = "Bar"
353-
let finalMessageText = "Baz"
354-
355-
try listenConn.listen(channelName) { text in
356-
if text == messageText {
357-
completionHandlerExpectation1.fulfill()
358-
} else if text == finalMessageText {
359-
completionHandlerExpectation2.fulfill()
360-
}
361-
}.catch({ err in XCTFail("error \(err)") })
362-
363-
try notifyConn.notify(channelName, message: messageText).wait()
364-
try notifyConn.notify(channelName, message: finalMessageText).wait()
365-
366-
waitForExpectations(timeout: defaultTimeout)
367-
notifyConn.close()
368-
listenConn.close()
369-
}
370-
371-
func testNotifyAndListenOnMultipleChannels() throws {
372-
let completionHandlerExpectation1 = expectation(description: "first completion handler called")
373-
let completionHandlerExpectation2 = expectation(description: "final completion handler called")
374-
let notifyConn = try PostgreSQLConnection.makeTest()
375-
let listenConn = try PostgreSQLConnection.makeTest()
376-
let channelName = "Fooze"
377-
let channelName2 = "Foozalz"
378-
let messageText = "Bar"
379-
let finalMessageText = "Baz"
380-
381-
try listenConn.listen(channelName) { text in
382-
if text == messageText {
383-
completionHandlerExpectation1.fulfill()
384-
}
385-
}.catch({ err in XCTFail("error \(err)") })
386-
387-
try listenConn.listen(channelName2) { text in
388-
if text == finalMessageText {
389-
completionHandlerExpectation2.fulfill()
390-
}
391-
}.catch({ err in XCTFail("error \(err)") })
392-
393-
try notifyConn.notify(channelName, message: messageText).wait()
394-
try notifyConn.notify(channelName2, message: finalMessageText).wait()
395-
396-
waitForExpectations(timeout: defaultTimeout)
397-
notifyConn.close()
398-
listenConn.close()
399-
}
400-
401-
func testUnlisten() throws {
402-
let unlistenHandlerExpectation = expectation(description: "unlisten completion handler called")
403-
404-
let listenHandlerExpectation = expectation(description: "listen completion handler called")
405-
406-
let notifyConn = try PostgreSQLConnection.makeTest()
407-
let listenConn = try PostgreSQLConnection.makeTest()
408-
let channelName = "Foozers"
409-
let messageText = "Bar"
410-
411-
try listenConn.listen(channelName) { text in
412-
if text == messageText {
413-
listenHandlerExpectation.fulfill()
414-
}
415-
}.catch({ err in XCTFail("error \(err)") })
416-
417-
try notifyConn.notify(channelName, message: messageText).wait()
418-
try notifyConn.unlisten(channelName, unlistenHandler: {
419-
unlistenHandlerExpectation.fulfill()
420-
}).wait()
421-
waitForExpectations(timeout: defaultTimeout)
422-
notifyConn.close()
423-
listenConn.close()
424-
}
346+
// func testNotifyAndListen() throws {
347+
// let completionHandlerExpectation1 = expectation(description: "first completion handler called")
348+
// let completionHandlerExpectation2 = expectation(description: "final completion handler called")
349+
// let notifyConn = try PostgreSQLConnection.makeTest()
350+
// let listenConn = try PostgreSQLConnection.makeTest()
351+
// let channelName = "Fooze"
352+
// let messageText = "Bar"
353+
// let finalMessageText = "Baz"
354+
//
355+
// try listenConn.listen(channelName) { text in
356+
// if text == messageText {
357+
// completionHandlerExpectation1.fulfill()
358+
// } else if text == finalMessageText {
359+
// completionHandlerExpectation2.fulfill()
360+
// }
361+
// }.catch({ err in XCTFail("error \(err)") })
362+
//
363+
// try notifyConn.notify(channelName, message: messageText).wait()
364+
// try notifyConn.notify(channelName, message: finalMessageText).wait()
365+
//
366+
// waitForExpectations(timeout: defaultTimeout)
367+
// notifyConn.close()
368+
// listenConn.close()
369+
// }
370+
//
371+
// func testNotifyAndListenOnMultipleChannels() throws {
372+
// let completionHandlerExpectation1 = expectation(description: "first completion handler called")
373+
// let completionHandlerExpectation2 = expectation(description: "final completion handler called")
374+
// let notifyConn = try PostgreSQLConnection.makeTest()
375+
// let listenConn = try PostgreSQLConnection.makeTest()
376+
// let channelName = "Fooze"
377+
// let channelName2 = "Foozalz"
378+
// let messageText = "Bar"
379+
// let finalMessageText = "Baz"
380+
//
381+
// try listenConn.listen(channelName) { text in
382+
// if text == messageText {
383+
// completionHandlerExpectation1.fulfill()
384+
// }
385+
// }.catch({ err in XCTFail("error \(err)") })
386+
//
387+
// try listenConn.listen(channelName2) { text in
388+
// if text == finalMessageText {
389+
// completionHandlerExpectation2.fulfill()
390+
// }
391+
// }.catch({ err in XCTFail("error \(err)") })
392+
//
393+
// try notifyConn.notify(channelName, message: messageText).wait()
394+
// try notifyConn.notify(channelName2, message: finalMessageText).wait()
395+
//
396+
// waitForExpectations(timeout: defaultTimeout)
397+
// notifyConn.close()
398+
// listenConn.close()
399+
// }
400+
//
401+
// func testUnlisten() throws {
402+
// let unlistenHandlerExpectation = expectation(description: "unlisten completion handler called")
403+
//
404+
// let listenHandlerExpectation = expectation(description: "listen completion handler called")
405+
//
406+
// let notifyConn = try PostgreSQLConnection.makeTest()
407+
// let listenConn = try PostgreSQLConnection.makeTest()
408+
// let channelName = "Foozers"
409+
// let messageText = "Bar"
410+
//
411+
// try listenConn.listen(channelName) { text in
412+
// if text == messageText {
413+
// listenHandlerExpectation.fulfill()
414+
// }
415+
// }.catch({ err in XCTFail("error \(err)") })
416+
//
417+
// try notifyConn.notify(channelName, message: messageText).wait()
418+
// try notifyConn.unlisten(channelName, unlistenHandler: {
419+
// unlistenHandlerExpectation.fulfill()
420+
// }).wait()
421+
// waitForExpectations(timeout: defaultTimeout)
422+
// notifyConn.close()
423+
// listenConn.close()
424+
// }
425425

426426
func testURLParsing() throws {
427427
let databaseURL = "postgres://username:password@hostname.com:5432/database"
@@ -442,9 +442,9 @@ class PostgreSQLConnectionTests: XCTestCase {
442442
("testStruct", testStruct),
443443
("testNull", testNull),
444444
("testGH24", testGH24),
445-
("testNotifyAndListen", testNotifyAndListen),
446-
("testNotifyAndListenOnMultipleChannels", testNotifyAndListenOnMultipleChannels),
447-
("testUnlisten", testUnlisten),
445+
// ("testNotifyAndListen", testNotifyAndListen),
446+
// ("testNotifyAndListenOnMultipleChannels", testNotifyAndListenOnMultipleChannels),
447+
// ("testUnlisten", testUnlisten),
448448
("testURLParsing", testURLParsing),
449449
]
450450
}

0 commit comments

Comments
 (0)