-
-
Notifications
You must be signed in to change notification settings - Fork 69
Notify listen #54
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
Notify listen #54
Conversation
Dbkit gm
…h of words, wow I can't belive I missed this
| func testUnlisten() throws { | ||
| let completionHandlerExpectation = expectation(description: "notify completion handler called") | ||
| completionHandlerExpectation.expectedFulfillmentCount = 2 | ||
| completionHandlerExpectation.assertForOverFulfill = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MrMage do you know of an alternative for these guys on Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid not :-/ I normally solve this by storing all the results provided to the callback handler in a separate array, and once I’ve waited for all expectations, I Test the array‘s contents using regular XCTest methods.
| _ = executeCloseHandlersThenClose() | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not: extra newline and two spaces before „func“
| let listenConn = try PostgreSQLConnection.makeTest() | ||
| let channelName = "Foo" | ||
| let channelName = "Fooze" | ||
| let messageText = "Bar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: also test with a message text longer than 3 characters, and test with an empty message? (See above.)
| self.message = message ?? channelId | ||
| _ = try container.decode(Int32.self) | ||
| channel = try container.decode(String.self) | ||
| message = try container.decode(String.self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres allows for now message to be provided, so I think message should be an optional and this an optional decode? Or will the message simply be empty in that case? (At least worth testing.)
| let query = PostgreSQLQuery(query: "NOTIFY \"\(channelName)\", '\(message)';") | ||
| return send([.query(query)]).map(to: Void.self, { _ in }) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postgres‘ notify command allows omitting the payload, so how about allowingNil messages in notify?
| unlistenHandlerExpectation.fulfill() | ||
| }).wait() | ||
| waitForExpectations(timeout: defaultTimeout) | ||
| notifyConn.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also test that no further notifications are sent after unlisten has been called.
@tanner0101 sorry about the terrible confusion