1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00
Commit Graph

1904 Commits

Author SHA1 Message Date
Richard van der Hoff
f1c5b632cc Deflake the matrixclient syncing tests (#498)
All of these tests were vulnerable to a race wherein we would flush the /sync
request, but the client had not yet processed the results before we checked
them. We can solve all of this by waiting for the client to emit a "sync"
event.
2017-07-14 16:09:28 +01:00
Richard van der Hoff
04ca0ac2b5 Give the megolm tests longer to complete
All that crypto stuff takes a while, so give it longer than 100ms.
2017-07-14 15:22:08 +01:00
Richard van der Hoff
8b2fdf3a75 Deflake megolm unit test
Waiting for 1ms isn't actually good enough. wait for the actual thing we are
actually waiting for.
2017-07-14 15:22:08 +01:00
Richard van der Hoff
adca75b7d8 Deflake matrix-client-timeline tests
These guys do a flush("/sync"), without waiting for it to complete, and then in
the afterEach, check that the sync has been flushed, which it may not have
been. So we should make sure we wait for the flush.
2017-07-14 15:22:08 +01:00
Richard van der Hoff
504fa2a1d3 Fix racy 'matrixclient retrying' test
when a message send fails, the promise returned by `sendMessage` is
rejected. Until we switched to bluebird, the rejection was happily being
swallowed, but with bluebird, there's a better chance of the unhandled
rejection being caught by the runtime and mocha and failing the test.
2017-07-13 18:18:21 +01:00
Richard van der Hoff
cfffbc4a09 replace q method calls with bluebird ones
```
find src spec -name '*.js' |
    xargs perl -i -pe 's/q\.(all|defer|reject|delay|try)\(/Promise.$1(/'
```
2017-07-12 23:33:55 +01:00
Richard van der Hoff
a5d3dd942e q(...) -> Promise.resolve
```
find src spec -name '*.js' |
    xargs perl -i -pe 's/\bq(\([^(]*\))/Promise.resolve$1/'
```
2017-07-12 23:32:28 +01:00
Richard van der Hoff
b96062b6de replace imports of q with bluebird
```
find src spec -name '*.js' |
   xargs perl -i -pe 'if (/require\(.q.\)/) { $_ = "import Promise from '\''bluebird'\'';\n"; }'

find src spec -name '*.js' |
   xargs perl -i -pe 'if (/import q/) { $_ = "import Promise from '\''bluebird'\'';\n"; }'
```
2017-07-12 23:32:28 +01:00
Richard van der Hoff
651baefb1d Remove redundant expectations
Apparently we weren't hitting these expected requests, so let's get rid of them.
2017-07-12 17:25:59 +01:00
Richard van der Hoff
ff7e845615 remove redundant flushAllExpected
Turned out this flush was completely redundant
2017-07-12 17:23:11 +01:00
Richard van der Hoff
f0612a1407 Fix some more flakey tests
switch a bunch of `flush()`es to `flushAllExpected()`s
2017-07-12 16:28:21 +01:00
Richard van der Hoff
83bd24adf8 More test deflakifying (#491)
Call `flushAllExpected()` from some more places. In a couple of places, we were
apparently calling `flush()` redundantly, so remove it altogether.
2017-07-12 14:05:39 +01:00
Richard van der Hoff
0ca4d728d8 Fix a bunch of races in the tests
Once we switch to bluebird, suddenly a load of timing issues come out of the
woodwork. Basically, we need to try harder when flushing requests. Bump to
matrix-mock-request 1.1.0, which provides `flushAllExpected`, and waits for
requests to arrive when given a `numToFlush`; then use `flushAllExpected` in
various places to make the tests more resilient.
2017-07-11 12:09:21 +01:00
David Baker
b2c7804032 Merge pull request #487 from matrix-org/rav/fix_bad_all_usage
Fix early return in MatrixClient.setGuestAccess
2017-07-11 11:21:45 +01:00
Richard van der Hoff
3bfb4595cf Remove redundant calls to done
These tests which return a promise already don't need to call `done`.
2017-07-10 17:40:23 +01:00
Richard van der Hoff
8955d8de23 remove utils.failTest
this is no longer used, so kill it
2017-07-10 17:25:56 +01:00
Richard van der Hoff
1372b298bb kill off more utils.failTest refs
manual replacement of some more complicated utils.failTest usages with q.all()
invocations.
2017-07-10 17:25:48 +01:00
Richard van der Hoff
9558845e6e Fix early return in MatrixClient.setGuestAccess
(as well as a similar bug in the test suite)

Turns out that `q.all(a, b)` === `q.all([a])`, rather than `q.all([a,b])`: it
only waits for the *first* promise - which means that `client.setGuestAccess`
would swallow any errors returned from the API.
2017-07-10 17:14:52 +01:00
Richard van der Hoff
5ab0930de8 utils.failTest -> nodeify
Automated replacement of utils.failTest with nodeify

This was done with the perl incantation:

```
    find spec -name '*.js' |
        xargs perl -i -pe 's/catch\((testUtils|utils).failTest\).done\(done\)/nodeify(done)/'
```

more auto
2017-07-10 16:37:31 +01:00
Richard van der Hoff
adc2070ac1 Merge pull request #483 from matrix-org/rav/remove_new_device_support
Remove m.new_device support
2017-07-06 17:10:37 +01:00
Richard van der Hoff
a8642682d0 Remove m.new_device support
We now rely on the server to track new devices, and tell us about them when
users add them, rather than forcing devices to announce themselves (see
https://github.com/vector-im/riot-web/issues/2305 for the whole backstory
there).

The necessary support for that has now been in all the clients and the server
for several months (since March or so). I now want to get rid of the
localstorage store, which this code is relying on, so now seems like a good
time to get rid of it. Yay.
2017-07-06 16:05:40 +01:00
Kegsay
d66e6db480 Merge pull request #478 from krombel/access_token_header
Use access-token in header
2017-07-06 13:44:31 +01:00
Richard van der Hoff
f21ea6c065 Extend timeout in megolm test
Use the default timeout of 100ms when waiting for the /send request, instead of
clamping it to 20ms.
2017-07-05 15:08:50 +01:00
Richard van der Hoff
b6a165f1f8 Merge branch 'develop' into rav/error_parsing 2017-07-04 16:03:33 +01:00
Richard van der Hoff
0d24f2d4c1 Use external mock-request
mock-request is now factored out to matrix-mock-request; use it
2017-07-04 15:45:22 +01:00
Krombel
07868f701a Merge remote-tracking branch 'upstream/develop' into access_token_header 2017-07-04 15:28:17 +02:00
Richard van der Hoff
ae950a2ff4 Fix some races in the tests
There is a common pattern in the tests which is, when we want to mock a /sync,
to flush it, and then, in the next tick of the promise loop, to wait for the
syncing event. However, this is racy: there is no guarantee that the syncing
event will not happen before the next tick of the promise loop.

Instead, we should set the expectation of the syncing event, then do the flush.
(Technically we only need to wait for the syncing event, but by waiting for
both we'll catch any errors thrown by the flush, and make sure we don't have
any outstanding flushes before proceeding).

Add a utility method to TestClient to do the above, and use it where we have a
TestClient.

(Also fixes a couple of other minor buglets in the tests).
2017-07-04 13:48:26 +01:00
Richard van der Hoff
5f6e4bdfe9 Avoid parsing plain-text errors as JSON
It's somewhat unhelpful to spam over the actual error from the reverse-proxy or
whatever with a SyntaxError.
2017-07-03 19:30:23 +01:00
Krombel
d36b8721ca Allow Authorization-Header in tests 2017-06-23 15:49:07 +02:00
Krombel
9b24e66441 Merge branch 'develop' into access_token_header 2017-06-23 15:16:41 +02:00
Richard van der Hoff
6055f038ee Fix a race in a test
startClient was written in such a way that it would leave a flush() running,
which could sometimes interfere with the rest of the test (or even subsequent
tests), causing sporadic test failures. Make sure that the flush completes
before we move on.

Fix a test which turned out to be relying on that behaviour (there was a flush
which ended up being a no-op, thus effectively inserting a pause allowing the
sync promise to complete.

Fix a beforeEach handler which was relying on startClient resolving to
undefined.
2017-06-21 07:57:38 +01:00
Richard van der Hoff
1f86dbd12f Add support for forwarding room keys to megolm
when we receive a m.forwarded_room_key, add it to the crypto store, but
remember who forwarded it to us, so we can decide whether to trust them
separately.
2017-06-20 12:39:36 +01:00
Richard van der Hoff
be3fb0f917 Make a start on a unit test for megolm alg impl
not much here yet, but it's a start at least.
2017-06-20 11:51:30 +01:00
Richard van der Hoff
e2f4c0ffd1 Rename megolm integration tests
I'm going to introduce some separate unit tests, so let's give this a different
filename to reduce confusion.
2017-06-20 11:51:11 +01:00
Richard van der Hoff
e6b35a9237 Run the crypto tests under travis (#467)
The crypto tests haven't been running since things got rearranged to expect
Olm in a global (41864d4). Reinstate them.
2017-06-20 10:44:03 +01:00
Richard van der Hoff
06b956bd75 disable e2e test when there is no e2e 2017-06-01 13:16:10 +01:00
Richard van der Hoff
655be2fa2e Fix race in device list updates
Don't consider device lists up-to-date when we have another request for the
relevant user in the queue.

Fixes https://github.com/vector-im/riot-web/issues/3796.
2017-05-05 12:34:00 +01:00
Richard van der Hoff
5020d4e99f Rework device list tracking logic (#425)
Yet another attempt at fixing
https://github.com/vector-im/riot-web/issues/2305.

This now implements the algorithm described at
http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#tracking-the-device-list-for-a-user:

* We now keep a flag to tell us which users' device lists we are tracking. That
  makes it much easier to figure out whether we should care about device-update
  notifications from /sync (thereby fixing
  https://github.com/vector-im/riot-web/issues/3588).

* We use the same flag to indicate whether the device list for a particular
  user is out of date. Previously we did this implicitly by only updating the
  stored sync token when the list had been updated, but that was somewhat
  complicated, and in any case didn't help in cases where we initiated the key
  download due to a user joining an encrypted room.

Also fixes https://github.com/vector-im/riot-web/issues/3310.
2017-04-25 17:56:01 +01:00
David Baker
cfff30c314 Use once to clean up listener 2017-04-07 11:10:57 +01:00
David Baker
18806e5524 lint 2017-04-06 16:58:13 +01:00
David Baker
bf6490739d Fix tests
Make setSyncData return promises in a few places and fix all the
places the tests assume that /sync being flushed == the sync
result being processed.
2017-04-06 15:20:50 +01:00
David Baker
b72b38b0a3 Add missed methods to stub/memory store
and fix tests
2017-04-03 17:45:58 +01:00
Kegan Dougal
c30670000d Handle 'limited' timeline responses in the SyncAccumulator
Fixes vector-im/riot-web#3375
2017-03-16 13:20:27 +00:00
David Baker
08a3aea1c7 Fix tests 2017-02-28 13:44:44 +00:00
Kegan Dougal
36b8b2c679 Unbreak tests. Add UT for account data 2017-02-21 11:51:45 +00:00
Richard van der Hoff
bbe74e6987 Merge pull request #376 from matrix-org/rav/delay_otk_generation
Upload one-time keys on /sync rather than a timer
2017-02-21 08:46:59 +00:00
Richard van der Hoff
98d606fca4 Upload one-time keys on /sync rather than a timer
Delay the upload of one-time keys until we have received a sync *without any
to-device messages*. Doing so means that we can try to avoid throwing away our
private keys just before we receive the to-device messages which use them.

Once we've decided to go ahead and upload them, we keep uploading them in
batches of 5 until we get to the desired 50 keys on the server. We then
periodically check that there are still enough on the server.
2017-02-20 16:26:24 +00:00
Kegan Dougal
5aa146f0a6 Add function to UTs 2017-02-17 10:41:04 +00:00
Kegan Dougal
c93c8a79b7 Add startup() to store API 2017-02-17 10:14:12 +00:00
Kegan Dougal
eedaacd256 Merge branch 'develop' into kegan/indexeddb 2017-02-16 16:10:56 +00:00