-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
fix: empty payload returned as list #4050
fix: empty payload returned as list #4050
Conversation
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.
@geisterfurz007 Would you be able to either include a test case or a screenshot of before and after in the PR description?
@stnguyen90 I could write a testcase in one of two ways:
I suppose 2 would be significantly simpler but I wasn't sure that is sufficient for you. A before and after of the serialization is demonstrated in the linked PHP sandbox; if a screenshot of the code / output is fine, I can certainly provide it from there, but I assume you mean from the actual backend? In case of the latter, I would opt for the test approach since I would otherwise build a full reproduction of the issue which would take quite some time, I think. Let me know which of the options works for you! |
@geisterfurz007, a test case would be an e2e test. I don't think you need to mock redis because our e2e tests run the full Appwrite stack |
Oh perfect, I will see what I can do then, thanks! |
I fiddled around with this for a while but I am not really sure what to do with this, to be honest. With the scenario described in the linked issue, I could not replicate the issue in the tests (there was an assertion for a non-empty payload in there even!) and I made an ugly attempt to manually send an empty payload but the receive call times out: public function testPayloadFormatOnDisconnect(): void
{
$client = $this->getWebsocket(['accounts']);
$response = $client->receive();
Realtime::send($this->getProject()['$id'], array(), array(), ['accounts'], ['role']);
$response = $client->receive();
$this->assertEquals('baked beans', $response); // Desperate way to get the content of $response into the console for debugging
} I would appreciate some guidance here; as said, I don't daily drive PHP and I have been struggling with this for some time now 😕 |
@geisterfurz007, here's a test where:
appwrite/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php Lines 384 to 397 in 4942ba9
appwrite/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php Lines 402 to 408 in 4942ba9
appwrite/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php Lines 409 to 426 in 4942ba9
Maybe you can use this for guidance. |
Right @stnguyen90, and there is one testcase that runs what I understood to be the problematic call in #3916: appwrite/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Lines 501 to 528 in 4942ba9
However in that testcase, there is an explicit assertion against an empty (deserialized) payload and indeed I could not reproduce an empty payload which is why I attempted to manually send one since I could not find any action that sends out an empty payload. |
@geisterfurz007, ah....looks like the problem happens specifically if 1 session is deleted from the Console. |
@stnguyen90 How about this approach then to make this tested in a bit more isolation (before I go about and more or less randomly throw PHP around): I move the json encoding of the payload / realtime JSON body to its own function and unit test that. It might not be a test for the full problem case specifically in the issue but should still cover what ended up crashing the JSON parser in flutter (returning an empty list instead of an empty object). |
So, I may have gone down the wrong rabbit hole on this problem. Apologies for that. The payload not be empty for a real event. In this case, it should be the deleted session. We do it for appwrite/app/controllers/api/account.php Lines 1823 to 1827 in 73bce1d
but the problem is it's missing from the Users API: appwrite/app/controllers/api/users.php Lines 1005 to 1007 in 73bce1d
Maybe you can add a test like appwrite/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Lines 501 to 528 in 4942ba9
but use the delete user session API with something like: appwrite/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Lines 1323 to 1328 in 4942ba9
|
@stnguyen90 I'm super sorry but I am getting more and more confused 😅 The API you linked appears to be the one used in the test I referred to (targeting P.S. If that makes things easier to coordinate, we can also move this discussion to Discord; I am geisterfurz007#5952 over there (also on the Appwrite server). |
So sorry! Yes, the Delete Account Session test is working as expected. I was suggesting creating a new test that would delete a session using the Users API like: $response = $this->client->call(Client::METHOD_DELETE, '/users/' . $userId . '/sessions' . $sessionId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], []); |
75ddaaa
to
1bd2249
Compare
Thank you so much for the PR 🤩. We're adding the |
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.
@geisterfurz007 something seems off with the CI...Perhaps syncing with master would fix this?
1bd2249
to
e891424
Compare
They ran through at least but a failure on a method I didn't touch 😕 I don't know if that's something that is looking familiar or if I should give it another shot locally tomorrow. What do you think @stnguyen90 ? |
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.
Seems like it was a flaky test. LGTM now! Thanks so much for this! 🙏🏼
@TorstenDittmann or @christyjacob4, would you please merge when you get a chance? |
THANK YOU! All changes merged 🥳 Please reach out to me on our Discord server if you would like to claim your Appwrite swags! As a way of saying thank you, we would also love to invite you to join the Appwrite organization on GitHub. Please share your GitHub username with us on Discord. You can accept the invite by visiting https://github.com/orgs/appwrite/invitation. By joining our team, you will officially be an Appwrite maintainer on GitHub. You can change your membership visibility settings, so your new Appwrite team membership badge will show up on your personal GitHub profile. Please feel free to look for more PRs you might be interested in helping with on our long list of Hacktoberfest friendly issues and help make Appwrite better :) |
What does this PR do?
This PR adds a
setPayload
call to theDELETE /user/:userId/sessions/:sessionId
endpoint which was previously missing causing the error described in #3916.Test Plan
An e2e test was written for the case to prevent regressions.
Related PRs and Issues
#3916
Have you read the Contributing Guidelines on issues?
Yes.