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

Timeout not working − stuck in infinite loop #716

Open
ebousse opened this issue Jun 5, 2020 · 3 comments
Open

Timeout not working − stuck in infinite loop #716

ebousse opened this issue Jun 5, 2020 · 3 comments
Labels
Milestone

Comments

@ebousse
Copy link

ebousse commented Jun 5, 2020

I encounter the strangest problem: in a project (from a student I supervise), I can never reach the end of the execution of his alsatian test suite.

At first I tried with:

alsatian './src/test/ts/*.spec.ts'

And it got stuck, then I tried with a timeout:

alsatian -t 1000 './src/test/ts/*.spec.ts'

But it also got stuck.

Then I played with the debugger, and I found out that alsatian was stuck inside this test case:

  @Test("A Queen can move vertically")
    testCanMoveVertically() {
        
        // Check the following moves are possible: moveE4_E1, moveE4_E8
        let positionE1 : Position = position(4, 0);
        let positionE8 : Position = position(4, 7);

        Expect ((isPossible.queenMove(chessboard, move(positionInitiale, positionE1))) && (isPossible.queenMove(chessboard, move(positionInitiale, positionE8)))).toBeTruthy();
    }

More precisely, it got stuck inside the queenMove call − itself inside the Expect − because of the faulty while loop it contains (which will be infinite in this case):

export function queenMove(board: Chessboard, move: Move): boolean {
    let chemin : Square = squareAtPosition(board, move.from!);
    //TODO: resuodre le probleme d'arret de boucle lié a chemin.isEmpty


    //validation mouvement rank
    if(move.from!.rank != move.to!.rank && move.from!.file == move.to!.file){
        while (chemin.position != move.to! && (squareAtPosition(board , position(chemin.position.file,chemin.position.rank + 1)).isEmpty || squareAtPosition(board , position(chemin.position.file,chemin.position.rank - 1)).isEmpty) ){
            if (chemin.position.rank < move.to!.rank) {
                chemin.position.rank++;
            }else{
                chemin.position.rank--;
            }
        }

I believe alsatian should stop after the given timeout in this situation?

@ebousse
Copy link
Author

ebousse commented Jun 5, 2020

Here is the faulty project:
chess-alsatian-problem.zip

Once in there, just run:

npm i
npm run test

@jamesadarich
Copy link
Member

@ebousse good find I would imagine this is because the main thread is being locked by the test. I was playing with pushing the running of tests to a worker thread so this could resolve the issue. I'll see if I can have an investigate in scope of 4.0.0 work :)

@jamesadarich jamesadarich added this to the 4.0.0 milestone Jun 7, 2020
@ebousse
Copy link
Author

ebousse commented Jun 12, 2020

Sounds great, looking forward to it! :)

@jamesadarich jamesadarich modified the milestones: 4.0.0, 5.0.0 Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants