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

Avoid race condition in GC_Example test #10665

Merged
merged 8 commits into from
Jul 29, 2024
12 changes: 5 additions & 7 deletions build/build/src/engine/context.rs
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,10 @@ pub async fn runner_sanity_test(
.args(["--run", repo_root.test.join("Base_Tests").as_str()])
.set_env_opt(ENSO_JAVA, enso_java)?
.set_env(ENSO_DATA_DIRECTORY, engine_package)?
.run_stdout()
.await?;
ensure!(
test_base.contains("0 tests failed."),
"All tests shall succeed. Output:\n{test_base}",
);
.run_ok()
.await;
test_base
} else {
Ok(())
}
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,34 @@ private final class ProcessItems extends ThreadLocalAction implements Runnable {
*/
@Override
protected void perform(ThreadLocalAction.Access access) {
var isMyThreadChoosen = false;
for (; ; ) {
Item[] toProcess;
synchronized (pendingItems) {
request.cancel(false);
if (!isMyThreadChoosen) {
if (request == null || request.isCancelled()) {
// some thread is already handing the request
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
return;
} else {
// I am choosen and I will loop and process pendingItems
// until they are available
isMyThreadChoosen = true;
// signal others this request has choosen thread
request.cancel(false);
}
}
if (pendingItems.isEmpty()) {
// nothing to process,
// signal request is finished
// nothing to process anymore,
// signal request is finished and new one shall be scheduled
request = null;
return;
}
toProcess = pendingItems.toArray(Item[]::new);
// mark as being processed
pendingItems.set(0, null);
pendingItems.clear();
}
try {
for (var it : toProcess) {
it.finalizeNow(context);
removeFromItems(it);
}
} finally {
synchronized (pendingItems) {
pendingItems.subList(0, toProcess.length).clear();
}
for (var it : toProcess) {
it.finalizeNow(context);
removeFromItems(it);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/Base_Tests/src/Runtime/GC_Example.enso
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type My_Resource

JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
close_resource resource = resource.close

repeat_cleanup_until_done counter =
repeat_cleanup_until_done counter println =
go i =
if counter.get == 0 then Nothing else
if i % 100 == 0 then
IO.println "Still "+counter.get.to_text+" resources to clean up..."
println "Still "+counter.get.to_text+" resources to clean up..."
Runtime.gc
@Tail_Call go i+1
go 1
Expand All @@ -32,7 +32,7 @@ perform_test n:Integer println =
My_Resource.allocate counter

println "Cleaning up..."
repeat_cleanup_until_done counter
repeat_cleanup_until_done counter println
println "All cleaned up! Remaining: "+counter.get.to_text
counter.get

Expand Down
4 changes: 2 additions & 2 deletions test/Base_Tests/src/Runtime/Managed_Resource_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ add_specs suite_builder = suite_builder.group "Managed_Resource" group_builder->
r_3 = Panic.recover Any <| Managed_Resource.bracket 42 (_-> Nothing) (_-> Panic.throw "action")
r_3.catch . should_equal "action"

group_builder.specify "allocate lots of resources at once" pending=(if Environment.get "CI" . is_nothing . not then "GC Example is marked as pending as it was causing problems on the CI.") <|
remaining = GC_Example.perform_test 100000 (_->Nothing)
group_builder.specify "allocate lots of resources at once" <|
remaining = GC_Example.perform_test 100000 IO.println
remaining . should_equal 0

main filter=Nothing =
Expand Down
Loading