-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixup deadlock when hammering futures of a certain type
- Loading branch information
Showing
5 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "regression-async-deadlock" | ||
edition = "2021" | ||
version = "0.0.1" | ||
authors = ["Filament Team <[email protected]>"] | ||
license = "MPL-2.0" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["lib", "staticlib", "cdylib"] | ||
name = "regression_async_deadlock" | ||
|
||
[patch.crates-io] | ||
async-compat = { git = "https://github.com/jplatte/async-compat", rev = "16dc8597ec09a6102d58d4e7b67714a35dd0ecb8" } | ||
const_panic = { git = "https://github.com/jplatte/const_panic", rev = "9024a4cb3eac45c1d2d980f17aaee287b17be498" } | ||
|
||
[dependencies] | ||
uniffi = { workspace = true } | ||
matrix-sdk-ffi = { workspace = true } | ||
matrix-sdk = { workspace = true } | ||
thiserror = "1.0" | ||
|
||
|
||
[build-dependencies] | ||
uniffi = { workspace = true, features = ["build"] } | ||
|
||
[dev-dependencies] | ||
uniffi = { workspace = true, features = ["bindgen-tests"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
||
use std::sync::Arc; | ||
|
||
use matrix_sdk_ffi::client_builder::ClientBuilder; | ||
|
||
#[uniffi::export] | ||
pub fn get_matrix_client_builder() -> Arc<ClientBuilder> { | ||
ClientBuilder::new() | ||
} | ||
|
||
uniffi::setup_scaffolding!(); |
107 changes: 107 additions & 0 deletions
107
fixtures/async-deadlock/tests/bindings/test_async_deadlock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
*/ | ||
|
||
import { asyncTest } from "@/asserts"; | ||
import { console } from "@/hermes"; | ||
import { | ||
ClientBuilder, | ||
ClientInterface, | ||
mediaSourceFromUrl, | ||
MediaSourceInterface, | ||
} from "../../generated/matrix_sdk_ffi"; | ||
|
||
import { delayPromise } from "uniffi-bindgen-react-native"; | ||
|
||
const url = "mxc://matrix.1badday.com/RUUIKNjovSSwYbULWuNQarDA"; | ||
|
||
(async () => { | ||
await asyncTest("Test delay promise", async (t) => { | ||
console.info("Starting delay"); | ||
await delayPromise(0); | ||
const start = Date.now(); | ||
await delayPromise(1000); | ||
const actual = Date.now() - start; | ||
console.info(`Ending delay, measured: ${actual} ms`); | ||
t.assertInRange(actual, 900, 1100); | ||
|
||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 8", async (t) => { | ||
await loadImages(8); | ||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 16", async (t) => { | ||
await loadImages(16); | ||
t.end(); | ||
}); | ||
|
||
|
||
await asyncTest("Test for deadlock 32", async (t) => { | ||
await loadImages(32); | ||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 64", async (t) => { | ||
await loadImages(64); | ||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 128", async (t) => { | ||
await loadImages(128); | ||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 256", async (t) => { | ||
await loadImages(256); | ||
t.end(); | ||
}); | ||
|
||
await asyncTest("Test for deadlock 512", async (t) => { | ||
await loadImages(512); | ||
t.end(); | ||
}, 30 * 1000); | ||
|
||
await asyncTest("Test for deadlock 1024", async (t) => { | ||
await loadImages(1024); | ||
t.end(); | ||
}, 60 * 1000); | ||
|
||
})(); | ||
|
||
async function loadImages(n: number): Promise<void> { | ||
const images = new Array(n).fill(url); | ||
const sourcedImages = images.map((i) => ({ | ||
source: mediaSourceFromUrl(i), | ||
})); | ||
const client = await new ClientBuilder() | ||
.homeserverUrl("https://matrix.1badday.com/") | ||
.build(); | ||
console.log("Starting…"); | ||
const promises = sourcedImages.map((s, i) => { | ||
console.log(`-- About to load image ${i}/${n}: ${s.source.url()}`); | ||
return client.getMediaContent(s.source).then((content) => { | ||
console.log(`-- Loaded image ${i}/${n}`, s.source.url()); | ||
}); | ||
}); | ||
await Promise.allSettled(promises); | ||
console.log("… finished"); | ||
} | ||
|
||
// (async function () { | ||
// const client = await new ClientBuilder() | ||
// .homeserverUrl("https://matrix.1badday.com/") | ||
// .build(); | ||
// const promises = sourcedImages.map((s) => { | ||
// console.log(`-- About to load ${s.source.url}`); | ||
// client.getMediaContent(s.source).then((content) => { | ||
// console.log("-- Loaded image: ", s.source.url()); | ||
// }); | ||
// }); | ||
|
||
// await Promise.allSettled(promises); | ||
// })(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[bindings.typescript] | ||
isVerbose = true | ||
consoleImport = "@/hermes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters