File tree Expand file tree Collapse file tree
src/test/java/org/carlmontrobotics/lib199 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import static org .junit .Assert .assertTrue ;
66import static org .junit .Assume .assumeNoException ;
77
8+ import java .util .concurrent .CountDownLatch ;
89import java .util .concurrent .atomic .AtomicBoolean ;
910
1011import com .ctre .phoenix .ErrorCode ;
@@ -234,21 +235,28 @@ private void doTestReportSparkMaxTemp(int id) {
234235 private AutoCloseable blockAsyncPeriodic () {
235236 AtomicBoolean block = new AtomicBoolean (true );
236237 Object lock = new Object ();
238+ CountDownLatch latch = new CountDownLatch (1 );
237239 Lib199Subsystem .registerAsyncPeriodic (() -> {
238240 synchronized (lock ) {
239- while (block .get ()) {
241+ latch .countDown (); // Signal that we've started blocking
242+ while (block .get ()) { // Block until released
240243 try {
241- lock .wait ();
244+ lock .wait (); // Wait for the block to be released
242245 } catch (InterruptedException e ) {
243246 assumeNoException (e );
244247 }
245248 }
246249 }
247250 });
251+ try {
252+ latch .await (); // Wait for the async thread to start blocking
253+ } catch (InterruptedException e ) {
254+ assumeNoException (e );
255+ }
248256 return () -> {
249- block .set (false );
257+ block .set (false ); // Release the block
250258 synchronized (lock ) {
251- lock .notifyAll ();
259+ lock .notifyAll (); // Notify the async thread that the block has been released
252260 }
253261 };
254262 }
You can’t perform that action at this time.
0 commit comments