Skip to content
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

Change Store.save() to return a Promise #3221

Merged
merged 2 commits into from
Apr 11, 2023

Conversation

texuf
Copy link
Contributor

@texuf texuf commented Mar 20, 2023

The only implementation of this is an async function, but I can’t await it because the interface hides the return type.

signed-off-by austin ellis austin@hntlabs.com

Type: defect


Here's what your changelog entry will look like:

🚨 BREAKING CHANGES

  • Change Store.save() to return a Promise (#3221). Contributed by @texuf.

The only implementation of this is an async function, but I can’t await it because the interface hides the return type.
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@texuf thanks for your contribution!

I think I'm missing some context on this. Is there a particular problem you are trying to solve?

I don't think IStore.save is meant to be used from outside the js-sdk (though I could be wrong on this; it's not an area I'm terribly familiar with). My understanding is that it is automatically called from sync.ts as part of the /sync loop, so I'm curious as to your usecase.

I'm also not sure that it matters that we don't wait for the promise to complete - there's not much we can do with the knowledge in any case.

@richvdh
Copy link
Member

richvdh commented Mar 23, 2023

@t3chguy I see you've labelled this as a breaking change, but we're changing a method that returned void into one which returns something else (a Promise, in this case). I don't think there's any way that can break existing application code unless someone was inexplicably relying on save to return undefined?

@t3chguy
Copy link
Member

t3chguy commented Mar 23, 2023

@richvdh typescript strict mode can get unhappy about this scenario

@texuf
Copy link
Contributor Author

texuf commented Mar 23, 2023

@texuf thanks for your contribution!

I think I'm missing some context on this. Is there a particular problem you are trying to solve?

I don't think IStore.save is meant to be used from outside the js-sdk (though I could be wrong on this; it's not an area I'm terribly familiar with). My understanding is that it is automatically called from sync.ts as part of the /sync loop, so I'm curious as to your usecase.

I'm also not sure that it matters that we don't wait for the promise to complete - there's not much we can do with the knowledge in any case.

I am writing tests where I'd like to verify that the saved sync interacts as I would expect with my application code.
My tests do the following

  • matrixClient.store.save(true) // necessary because the store saves periodically, I would like to force a write
  • matrixClient.stopClient()
  • matrixClient = undefined

Then I go on to create a new matrix client with the same credentials (simulating a browser refresh) and verify that the saved sync is loaded and correctly populates my ui

If I don't wait for the save to complete, I have unreliable tests because I don't know when the async operation has completed.

I think there will be instances in the future where I will want to ensure data is persisted before performing a user action, but that is speculation, the main use case is for writing reliable tests.

@richvdh richvdh self-requested a review March 24, 2023 10:49
@richvdh richvdh changed the title Update storage interface so that save() is async to match indexeddb impl Change Store.save() to return a Promise Mar 24, 2023
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fair. Thanks for the explanation!

@richvdh richvdh added this pull request to the merge queue Mar 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 24, 2023
@texuf
Copy link
Contributor Author

texuf commented Mar 24, 2023

Can anyone help me with this downstream test error?

0s
Run exit [1](https://github.com/matrix-org/matrix-js-sdk/actions/runs/4513595824/jobs/7949013225#step:2:1)
  exit 1
  shell: /usr/bin/bash -e {0}
Error: Process completed with exit code [1](https://github.com/matrix-org/matrix-js-sdk/actions/runs/4513595824/jobs/7949013225#step:3:1).

not sure what do here.

@texuf
Copy link
Contributor Author

texuf commented Mar 24, 2023

Can anyone help me with this downstream test error?

0s
Run exit [1](https://github.com/matrix-org/matrix-js-sdk/actions/runs/4513595824/jobs/7949013225#step:2:1)
  exit 1
  shell: /usr/bin/bash -e {0}
Error: Process completed with exit code [1](https://github.com/matrix-org/matrix-js-sdk/actions/runs/4513595824/jobs/7949013225#step:3:1).

not sure what do here.

Ah i see, a previous test failed, still not sure if this is on me

Error: expect(element).toHaveAttribute("contentEditable", "true") // element.getAttribute("contentEditable") === "true"

Expected the element to have attribute:
  contentEditable="true"
Received:
  contentEditable="false"

@richvdh
Copy link
Member

richvdh commented Mar 24, 2023

Yeah, I don't understand this either. I've asked for help from the rest of the team but it's Friday evening now.

@t3chguy
Copy link
Member

t3chguy commented Mar 27, 2023

Looks like a WYSIWYG test is flaky

@t3chguy t3chguy added this pull request to the merge queue Mar 27, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 27, 2023
@texuf
Copy link
Contributor Author

texuf commented Apr 4, 2023

@t3chguy do you think we could try the merge queue again?

@richvdh richvdh added this pull request to the merge queue Apr 4, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 4, 2023
@richvdh
Copy link
Member

richvdh commented Apr 4, 2023

This does seem to be causing an actual failure, unfortunately

@richvdh
Copy link
Member

richvdh commented Apr 4, 2023

possibly the problem is that we are now waiting for IndexedDBStore.save() to complete, whereas previously it would still fail, but scream its errors into the void?

@texuf
Copy link
Contributor Author

texuf commented Apr 4, 2023

possibly the problem is that we are now waiting for IndexedDBStore.save() to complete, whereas previously it would still fail, but scream its errors into the void?

Thanks for looking into it. I will see if I can figure it out later tonight.

@texuf
Copy link
Contributor Author

texuf commented Apr 6, 2023

I don't see much difference between my run and a successful one, the output is pretty rough to look at. I created a PR for the only thing I could find: element-hq/element-web#25061

@richvdh richvdh self-requested a review April 11, 2023 12:51
@richvdh
Copy link
Member

richvdh commented Apr 11, 2023

the output is pretty rough to look at.

It absolutely is. I think this is mostly a result of our jest configuration; #3269 should improve that for the js-sdk, and I'll replicate it for the other projects soon. (Though also, the failing test uses matrix-mock-request, which is... crap.)

However, on closer inspection of the logs from the failed run, it seems like the failure mode is already known, so I'm going to mash the merge button again. Sorry for the run-around on this.

@richvdh richvdh added this pull request to the merge queue Apr 11, 2023
Merged via the queue into matrix-org:develop with commit a102253 Apr 11, 2023
@texuf texuf deleted the austin.ellis/async-storage-save branch April 17, 2023 19:30
texuf added a commit to texuf/matrix-js-sdk that referenced this pull request Apr 17, 2023
…mpl (matrix-org#3221)

The only implementation of this is an async function, but I can’t await it because the interface hides the return type.

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
su-ex added a commit to SchildiChat/matrix-js-sdk that referenced this pull request Apr 25, 2023
* Change `Store.save()` to return a `Promise` ([\matrix-org#3221](matrix-org#3221)). Contributed by @texuf.
* Add typedoc-plugin-mdn-links ([\matrix-org#3292](matrix-org#3292)).
* Annotate events with executed push rule ([\matrix-org#3284](matrix-org#3284)). Contributed by @kerryarchibald.
* Element-R: pass device list change notifications into rust crypto-sdk ([\matrix-org#3254](matrix-org#3254)). Fixes element-hq/element-web#24795. Contributed by @florianduros.
* Support for MSC3882 revision 1 ([\matrix-org#3228](matrix-org#3228)). Contributed by @hughns.
* Fix screen sharing on Firefox 113 ([\matrix-org#3282](matrix-org#3282)). Contributed by @tulir.
* Retry processing potential poll events after decryption ([\matrix-org#3246](matrix-org#3246)). Fixes element-hq/element-web#24568.
* Element-R: handle events which arrive before their keys ([\matrix-org#3230](matrix-org#3230)). Fixes element-hq/element-web#24489.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Defect X-Breaking-Change Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants