From 24dd54482514def459b43c47e689d48d6a1c9930 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:51:25 -0400 Subject: [PATCH] [wpilib] Wait 0.5s after enabling interrupt in tests (#6891) If the interrupt edge tests are running while under heavy CPU load (like building wpilib) they are prone to failure since the interrupt thread doesn't have enough time to set up callbacks. The interrupt edge tests now copy the original AsynchronousInterrupt test, which has a 0.5s delay after the interrupt is enabled. Running the new interrupt tests while building allwpilib causes far less failures than the old tests. --- wpilibc/src/test/native/cpp/InterruptTest.cpp | 6 ++---- .../src/test/java/edu/wpi/first/wpilibj/InterruptTest.java | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/wpilibc/src/test/native/cpp/InterruptTest.cpp b/wpilibc/src/test/native/cpp/InterruptTest.cpp index d0cc2c0822..8b054d75f5 100644 --- a/wpilibc/src/test/native/cpp/InterruptTest.cpp +++ b/wpilibc/src/test/native/cpp/InterruptTest.cpp @@ -57,9 +57,8 @@ TEST(InterruptTest, RisingEdge) { interrupt.SetInterruptEdges(true, true); DIOSim digitalSim{di}; digitalSim.SetValue(false); - frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(0.5_s); digitalSim.SetValue(true); frc::Wait(20_ms); @@ -87,9 +86,8 @@ TEST(InterruptTest, FallingEdge) { interrupt.SetInterruptEdges(true, true); DIOSim digitalSim{di}; digitalSim.SetValue(true); - frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(0.5_s); digitalSim.SetValue(false); frc::Wait(20_ms); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java index a392fc6c8e..7855d89753 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java @@ -62,9 +62,8 @@ class InterruptTest { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); digitalSim.setValue(false); - Timer.delay(0.5); interrupt.enable(); - Timer.delay(0.02); + Timer.delay(0.5); digitalSim.setValue(true); Timer.delay(0.02); @@ -99,9 +98,8 @@ class InterruptTest { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); digitalSim.setValue(true); - Timer.delay(0.5); interrupt.enable(); - Timer.delay(0.02); + Timer.delay(0.5); digitalSim.setValue(false); Timer.delay(0.02);