Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
41fc243
CI run is working again, fix formatting
skeet70 Apr 4, 2025
ab40f45
Sort deps
skeet70 Apr 4, 2025
ac7d02b
Only the cancel, most likely problem?
skeet70 Apr 4, 2025
a3dc848
Add one of the errors back in
skeet70 Apr 4, 2025
cc446cb
Got failure with cancel + error, try just error
skeet70 Apr 4, 2025
45c7367
Switch to a different error case.
skeet70 Apr 4, 2025
d589263
Add a long delay after the error
skeet70 Apr 4, 2025
7bd633d
Dropping delay again
skeet70 Apr 4, 2025
8d93bc3
Add more info about timing
skeet70 Apr 4, 2025
65bcca1
Log in the free
skeet70 Apr 4, 2025
9a9a0dc
Remove only exceptional cases for some runs
skeet70 Apr 4, 2025
8e59d53
lots more logging
skeet70 Apr 7, 2025
a54f31c
Sorted
skeet70 Apr 7, 2025
d28f1f9
Add all the trait tests back in
skeet70 Apr 8, 2025
3723cc2
Try backing out uniffi logging to get reproduction back
skeet70 Apr 8, 2025
57caf86
Switch back to uniffi proper, and non-busy loop poll
skeet70 Apr 8, 2025
304d307
All the way back, drop logging
skeet70 Apr 8, 2025
f0bd0e4
Missed printlns
skeet70 Apr 8, 2025
38310fd
Stall for 10s before counting handles
skeet70 Apr 8, 2025
4770c17
What if more time
skeet70 Apr 8, 2025
43b0c6b
Back to busy waiting
skeet70 Apr 8, 2025
cf8e033
Add back in busy-wait in poll
skeet70 Apr 8, 2025
f6adc27
Catch the timeout
skeet70 Apr 8, 2025
eb51402
Don't need the polling log, can see from the time
skeet70 Apr 8, 2025
7b3add3
Make uniffi noisy again
skeet70 Apr 8, 2025
019b57a
Don't stall now that we know it doesn't fix with time
skeet70 Apr 8, 2025
c8da9c8
Try to narrow tests again
skeet70 Apr 8, 2025
cd46622
Couldn't reproduce without all tests
skeet70 Apr 8, 2025
b0d584b
Reproduced but still noisy, try again with less noise
skeet70 Apr 8, 2025
b9409aa
Try all adjacent tests, but only one trait test
skeet70 Apr 9, 2025
6717541
Add superficial java logging
skeet70 Apr 9, 2025
92d409c
Still reproducing, add some more logging
skeet70 Apr 9, 2025
1d98061
callback logging
skeet70 Apr 9, 2025
9f1ca50
Push up more logging around trait calls
skeet70 Apr 10, 2025
bcfc747
Log when FF is dropped on the rust side
skeet70 Apr 10, 2025
7a1ad30
Log if the FreeImpl is GCd to try to catch its weaker reference
skeet70 Apr 10, 2025
d6c8453
Try to log when GCd
skeet70 Apr 10, 2025
f37e22f
Test out the fix, singleton shouldn't ever get GCd
skeet70 Apr 10, 2025
7537504
Move the cancelable future up so it's in scope always
skeet70 Apr 10, 2025
f30e84e
Drop a bunch of logging
skeet70 Apr 10, 2025
6916196
Void test still failing because we're too slow
skeet70 Apr 10, 2025
ec06e25
Remove dead comment
skeet70 Apr 10, 2025
1f57c14
Remove dead import
skeet70 Apr 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
891 changes: 362 additions & 529 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ path = "src/main.rs"

[dependencies]
anyhow = "1"
rinja = { version = "0.3", default-features = false, features = ["config"] }
camino = "1.1.6"
cargo_metadata = "0.15"
clap = { version = "4", default-features = false, features = [
Expand All @@ -44,11 +43,14 @@ heck = "0.5"
once_cell = "1.19.0"
paste = "1"
regex = "1.10.4"
rinja = { version = "0.3", default-features = false, features = ["config"] }
serde = "1"
textwrap = "0.16.1"
toml = "0.5" # can't be on 8, `Value` is part of public interface
uniffi_bindgen = "0.29.1"
uniffi_meta = "0.29.1"
# uniffi_bindgen = "0.29.1"
uniffi_bindgen = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "noisy-test" }
# uniffi_meta = "0.29.1"
uniffi_meta = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "noisy-test" }

[dev-dependencies]
glob = "0.3"
Expand All @@ -60,6 +62,7 @@ uniffi-example-geometry = { git = "https://github.com/mozilla/uniffi-rs.git", ta
uniffi-example-rondpoint = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
uniffi-fixture-coverall = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
uniffi-fixture-ext-types = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
uniffi-fixture-futures = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
# uniffi-fixture-futures = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
uniffi-fixture-futures = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "noisy-test" }
uniffi-fixture-time = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
uniffi_testing = { git = "https://github.com/mozilla/uniffi-rs.git", tag = "v0.29.1" }
2 changes: 1 addition & 1 deletion src/gen_java/callback_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 super::{potentially_add_external_package, CodeType, Config};
use super::{CodeType, Config, potentially_add_external_package};
use crate::ComponentInterface;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/gen_java/compounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use super::{AsCodeType, CodeType, Config};
use uniffi_bindgen::{
backend::{Literal, Type},
ComponentInterface,
backend::{Literal, Type},
};

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/gen_java/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 super::{potentially_add_external_package, CodeType, Config};
use super::{CodeType, Config, potentially_add_external_package};
use crate::ComponentInterface;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/gen_java/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 super::{potentially_add_external_package, CodeType, Config};
use super::{CodeType, Config, potentially_add_external_package};
use crate::ComponentInterface;
use uniffi_bindgen::backend::Literal;

Expand Down
4 changes: 2 additions & 2 deletions src/gen_java/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 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 super::{potentially_add_external_package, CodeType, Config};
use uniffi_bindgen::{interface::ObjectImpl, ComponentInterface};
use super::{CodeType, Config, potentially_add_external_package};
use uniffi_bindgen::{ComponentInterface, interface::ObjectImpl};

#[derive(Debug)]
pub struct ObjectCodeType {
Expand Down
2 changes: 1 addition & 1 deletion src/gen_java/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 super::{potentially_add_external_package, CodeType, Config};
use super::{CodeType, Config, potentially_add_external_package};
use uniffi_bindgen::ComponentInterface;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/gen_java/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 super::{potentially_add_external_package, AsCodeType, CodeType, Config, JavaCodeOracle};
use super::{AsCodeType, CodeType, Config, JavaCodeOracle, potentially_add_external_package};
use uniffi_bindgen::interface::{ComponentInterface, Variant};

#[derive(Debug)]
Expand Down
7 changes: 2 additions & 5 deletions src/templates/Async.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ private static byte poll(long rustFuture, PollingFunction pollFunc) throws Inter
CompletableFuture<Byte> pollFuture = new CompletableFuture<>();
var handle = uniffiContinuationHandleMap.insert(pollFuture);
pollFunc.apply(rustFuture, UniffiRustFutureContinuationCallbackImpl.INSTANCE, handle);

// busy-wait until the poll completes
// TODO(java): may be more efficient to use a CountdownLatch here instead of a CF we end up busy-waiting
// because of Java bugs.
do {} while (!pollFuture.isDone());
do {} while (!pollFuture.isDone()); // removing this makes futures not cancel (sometimes)
return pollFuture.get();
}

Expand Down Expand Up @@ -221,6 +217,7 @@ static class UniffiForeignFutureFreeImpl<T> implements UniffiForeignFutureFree {

@Override
public void callback(long handle) {
System.out.println("java free impl called Handle(" + handle + ") " + System.currentTimeMillis());
var job = uniffiForeignFutureHandleMap.remove(handle);
var successfullyCancelled = job.cancel(true);
if(successfullyCancelled) {
Expand Down
66 changes: 36 additions & 30 deletions tests/scripts/TestFixtureFutures/TestFixtureFutures.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class TestFixtureFutures {
Expand Down Expand Up @@ -216,12 +217,14 @@ public CompletableFuture<Void> delay(Integer delayMs) {

@Override
public CompletableFuture<Void> tryDelay(String delayMs) {
System.out.println("java trait method executing " + System.currentTimeMillis());
try {
var parsed = Long.parseLong(delayMs);
return TestFixtureFutures.delay(parsed).thenRun(() -> {
completedDelays += 1;
});
} catch (NumberFormatException e) {
System.out.println("java trait method caught exception " + System.currentTimeMillis());
var f = new CompletableFuture<Void>();
f.completeExceptionally(new ParserException.NotAnInt());
return f;
Expand All @@ -230,29 +233,32 @@ public CompletableFuture<Void> tryDelay(String delayMs) {
}

var traitObj = new JavaAsyncParser();
assert Futures.asStringUsingTrait(traitObj, 1, 42).get().equals("42");
assert Futures.tryFromStringUsingTrait(traitObj, 1, "42").get().equals(42);
try {
Futures.tryFromStringUsingTrait(traitObj, 1, "fourty-two").get();
throw new RuntimeException("Expected last statement to throw");
} catch (ExecutionException e) {
if (e.getCause() instanceof ParserException.NotAnInt) {
// Expected
} else {
throw e;
}
}
try {
Futures.tryFromStringUsingTrait(traitObj, 1, "force-unexpected-exception").get();
throw new RuntimeException("Expected last statement to throw");
} catch (ExecutionException e) {
if (e.getCause() instanceof ParserException.UnexpectedException) {
// Expected
} else {
throw e;
}
}
Futures.delayUsingTrait(traitObj, 1).get();
var startingHandleCount = UniffiAsyncHelpers.uniffiForeignFutureHandleCount();
assert startingHandleCount == 0 : MessageFormat.format("{0} starting handle count != 0", startingHandleCount);
// assert Futures.asStringUsingTrait(traitObj, 1, 42).get().equals("42");
// assert Futures.tryFromStringUsingTrait(traitObj, 1, "42").get().equals(42);
// try {
// Futures.tryFromStringUsingTrait(traitObj, 1, "fourty-two").get();
// throw new RuntimeException("Expected last statement to throw");
// } catch (ExecutionException e) {
// if (e.getCause() instanceof ParserException.NotAnInt) {
// // Expected
// } else {
// throw e;
// }
// }
// try {
// Futures.tryFromStringUsingTrait(traitObj, 1, "force-unexpected-exception").get();
// throw new RuntimeException("Expected last statement to throw");
// } catch (ExecutionException e) {
// if (e.getCause() instanceof ParserException.UnexpectedException) {
// // Expected
// } else {
// throw e;
// }
// }
// Futures.delayUsingTrait(traitObj, 1).get();
System.out.println("calling for trait method from java test " + System.currentTimeMillis());
try {
Futures.tryDelayUsingTrait(traitObj, "one").get();
throw new RuntimeException("Expected last statement to throw");
Expand All @@ -263,15 +269,15 @@ public CompletableFuture<Void> tryDelay(String delayMs) {
throw e;
}
}
var completedDelaysBefore = traitObj.completedDelays;
Futures.cancelDelayUsingTrait(traitObj, 50).get();
// sleep long enough so that the `delay()` call would finish if it wasn't cancelled.
TestFixtureFutures.delay(200).get();
// If the task was cancelled, then completedDelays won't have increased
assert traitObj.completedDelays == completedDelaysBefore : MessageFormat.format("{0} current delays != {1} delays before", traitObj.completedDelays, completedDelaysBefore);
System.out.println("finished trait method from java test " + System.currentTimeMillis());
// var completedDelaysBefore = traitObj.completedDelays;
// Futures.cancelDelayUsingTrait(traitObj, 50).get();
// // sleep long enough so that the `delay()` call would finish if it wasn't cancelled.
// TestFixtureFutures.delay(200).get();
// // If the task was cancelled, then completedDelays won't have increased
// assert traitObj.completedDelays == completedDelaysBefore : MessageFormat.format("{0} current delays != {1} delays before", traitObj.completedDelays, completedDelaysBefore);

// Test that all handles were cleaned up
System.gc();
var endingHandleCount = UniffiAsyncHelpers.uniffiForeignFutureHandleCount();
assert endingHandleCount == 0 : MessageFormat.format("{0} current handle count != 0", endingHandleCount);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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 anyhow::{bail, Context, Result};
use anyhow::{Context, Result, bail};
use camino::{Utf8Path, Utf8PathBuf};
use cargo_metadata::{MetadataCommand, Package, Target};
use std::env::consts::ARCH;
Expand Down
Loading