From 0d95568972260b69cefb31ffa14ba10434faeba6 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 30 Dec 2022 14:34:44 -0500 Subject: [PATCH] chore: add miri and windows test --- .github/workflows/miri.yml | 72 ++++++++++++++++++++++++++++ packages/core/tests/miri_stress.rs | 77 ++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 .github/workflows/miri.yml diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml new file mode 100644 index 000000000..d1bba9964 --- /dev/null +++ b/.github/workflows/miri.yml @@ -0,0 +1,72 @@ +name: CI + +on: + push: + # Run in PRs and for bors, but not on master. + branches: + - 'auto' + - 'try' + pull_request: + branches: + - 'master' + schedule: + - cron: '6 6 * * *' # At 6:06 UTC every day. + +env: + CARGO_UNSTABLE_SPARSE_REGISTRY: 'true' + +jobs: + build: + runs-on: ${{ matrix.os }} + env: + RUST_BACKTRACE: 1 + HOST_TARGET: ${{ matrix.host_target }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + host_target: i686-pc-windows-msvc + steps: + - uses: actions/checkout@v3 + + # Cache the global cargo directory, but NOT the local `target` directory which + # we cannot reuse anyway when the nightly changes (and it grows quite large + # over time). + - name: Add cache for cargo + id: cache + uses: actions/cache@v3 + with: + path: | + # Taken from . + ~/.cargo/bin + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git/db + # contains package information of crates installed via `cargo install`. + ~/.cargo/.crates.toml + ~/.cargo/.crates2.json + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo + + - name: Install rustup-toolchain-install-master + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + shell: bash + run: | + cargo install -f rustup-toolchain-install-master + - name: Install "master" toolchain + shell: bash + run: | + if [[ ${{ github.event_name }} == 'schedule' ]]; then + echo "Building against latest rustc git version" + git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version + fi + ./miri toolchain --host ${{ matrix.host_target }} + - name: Show Rust version + run: | + rustup show + rustc -Vv + cargo -V + - name: Test + run: | + MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture diff --git a/packages/core/tests/miri_stress.rs b/packages/core/tests/miri_stress.rs index 160baa25d..5ceb8d528 100644 --- a/packages/core/tests/miri_stress.rs +++ b/packages/core/tests/miri_stress.rs @@ -137,6 +137,83 @@ fn free_works_on_root_hooks() { assert_eq!(Rc::strong_count(&ptr), 1); } +#[test] +fn supports_async() { + use std::time::Duration; + use tokio::time::sleep; + + fn app(cx: Scope) -> Element { + let colors = use_state(&cx, || vec!["green", "blue", "red"]); + let padding = use_state(&cx, || 10); + + use_effect(&cx, colors, |colors| async move { + sleep(Duration::from_millis(1000)).await; + colors.with_mut(|colors| colors.reverse()); + }); + + use_effect(&cx, padding, |padding| async move { + sleep(Duration::from_millis(10)).await; + padding.with_mut(|padding| { + if *padding < 65 { + *padding += 1; + } else { + *padding = 5; + } + }); + }); + + let big = colors[0]; + let mid = colors[1]; + let small = colors[2]; + + cx.render(rsx! { + div { + background: "{big}", + height: "stretch", + width: "stretch", + padding: "50", + label { + "hello", + } + div { + background: "{mid}", + height: "auto", + width: "stretch", + padding: "{padding}", + label { + "World", + } + div { + background: "{small}", + height: "auto", + width: "stretch", + padding: "20", + label { + "ddddddd", + } + } + }, + } + }) + } + + let rt = tokio::runtime::Builder::new_current_thread() + .enable_time() + .build() + .unwrap(); + + rt.block_on(async { + let mut dom = VirtualDom::new(app); + let _ = dom.rebuild(); + + for x in 0..10 { + let _ = dom.wait_for_work().await; + let edits = dom.render_immediate(); + dbg!(edits); + } + }); +} + // #[test] // fn old_props_arent_stale() { // fn app(cx: Scope) -> Element {