I have a function that needs to do something like "try to move to node X in a directed graph", and my current implementation uses an indefinite loop like this
while(true) {
trySomething();
if (checkAreWeThereYet()) {
break;
}
if (inferInfiniteLoopIsHappening()) {
throw;
}
}
But with the current implementation I haven't found a way (yet) to actually trigger an infinite loop and test that last part (which I added in precisely because there was a bug in a previous iteration of the code that led to an infinite loop) to make sure it's working as intended.
I've been thinking of mocking some of the implementation details to fake "making a mistake" that would then lead to an infinite loop, but that strikes me as maybe not a best practice (?)
The only online resources I've been able to find so far around this are for the "simpler" but analogous "switch statement's default case is currently unreachable, but might be hit if a bug is introduced in upstream code" scenario, but I'm wondering if I've just been googling the wrong terms (?)