question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit tests fail locally first time run, but succeed subsequent times

See original GitHub issue

Describe the bug I’ve noticed this a few times in past few weeks. It happened again today after pulling the latest main down locally.

To Reproduce Steps to reproduce the behavior:

In Terminal.Gui/ root on local machine:

  1. git pull upstream main
  2. dotnet test
  3. dotnet test

As shown below the first dotnet test fails. The 2nd passes.

Oddly, this does not reproduce if I do a dotnet clean and then dotnet test.

┌[charl@TIGGER] [ main ≣]
└[~\s\gui.cs]> git pull upstream main
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 7), reused 4 (delta 4), pack-reused 0
Unpacking objects: 100% (8/8), 1.70 KiB | 36.00 KiB/s, done.
From tig:migueldeicaza/gui.cs
 * branch              main       -> FETCH_HEAD
   56c28f6d..a9a0d176  main       -> upstream/main
Updating 56c28f6d..a9a0d176
Fast-forward
 Terminal.Gui/Core/View.cs       |  15 +++---
 UnitTests/ConsoleDriverTests.cs |   8 ++--
 UnitTests/ViewTests.cs          | 101 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 14 deletions(-)
┌[charl@TIGGER] [ main ↑1]
└[~\s\gui.cs]> git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To tig:tig/gui.cs
   56c28f6d..a9a0d176  main -> main
┌[charl@TIGGER] [ main ≣]
└[~\s\gui.cs]> dotnet test
  Determining projects to restore...
  Restored C:\Users\charlie\s\gui.cs\Example\Example.csproj (in 481 ms).
  Restored C:\Users\charlie\s\gui.cs\UICatalog\UICatalog.csproj (in 481 ms).
  Restored C:\Users\charlie\s\gui.cs\ReactiveExample\ReactiveExample.csproj (in 481 ms).
  Restored C:\Users\charlie\s\gui.cs\Terminal.Gui\Terminal.Gui.csproj (in 481 ms).
  Restored C:\Users\charlie\s\gui.cs\UnitTests\UnitTests.csproj (in 704 ms).
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\net472\Terminal.Gui.dll
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\netstandard2.0\Terminal.Gui.dll
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\net6.0\Terminal.Gui.dll
  UICatalog -> C:\Users\charlie\s\gui.cs\UICatalog\bin\Debug\net6.0\UICatalog.dll
  UnitTests -> C:\Users\charlie\s\gui.cs\UnitTests\bin\Debug\net6.0\UnitTests.dll
Test run for C:\Users\charlie\s\gui.cs\UnitTests\bin\Debug\net6.0\UnitTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:14.45]     Terminal.Gui.Core.MainLoopTests.AddTimer_Duplicate_Keys_Not_Allowed [FAIL]
  Failed Terminal.Gui.Core.MainLoopTests.AddTimer_Duplicate_Keys_Not_Allowed [1 ms]
  Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at Terminal.Gui.MainLoop.RunTimers() in C:\Users\charlie\s\gui.cs\Terminal.Gui\Core\MainLoop.cs:line 180
   at Terminal.Gui.MainLoop.MainIteration() in C:\Users\charlie\s\gui.cs\Terminal.Gui\Core\MainLoop.cs:line 241
   at Terminal.Gui.MainLoop.Run() in C:\Users\charlie\s\gui.cs\Terminal.Gui\Core\MainLoop.cs:line 260
   at Terminal.Gui.Core.MainLoopTests.AddTimer_Duplicate_Keys_Not_Allowed() in C:\Users\charlie\s\gui.cs\UnitTests\MainLoopTests.cs:line 292
--- End of stack trace from previous location ---

Failed!  - Failed:     1, Passed:   636, Skipped:     0, Total:   637, Duration: 9 s - UnitTests.dll (net6.0)
┌[charl@TIGGER] [ main ≣]
└[~\s\gui.cs]> dotnet test
  Determining projects to restore...
  All projects are up-to-date for restore.
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\net472\Terminal.Gui.dll
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\netstandard2.0\Terminal.Gui.dll
  Terminal.Gui -> C:\Users\charlie\s\gui.cs\Terminal.Gui\bin\Debug\net6.0\Terminal.Gui.dll
  UICatalog -> C:\Users\charlie\s\gui.cs\UICatalog\bin\Debug\net6.0\UICatalog.dll
  UnitTests -> C:\Users\charlie\s\gui.cs\UnitTests\bin\Debug\net6.0\UnitTests.dll
Test run for C:\Users\charlie\s\gui.cs\UnitTests\bin\Debug\net6.0\UnitTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:   637, Skipped:     0, Total:   637, Duration: 8 s - UnitTests.dll (net6.0)
┌[charl@TIGGER] [ main ≣]
└[~\s\gui.cs]>

Note this is the same set of tests that were intermittently failing for @bdisp’s PR #1606. But in that case it was w/in the GitHub environment.

Desktop (please complete the following information):

  • OS: Win11
  • dotnet: 6.0.200
  • VS 2022 Version 17.2.0 Preview 1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:26

github_iconTop GitHub Comments

1reaction
tigcommented, Aug 3, 2022

It’s in the github action.

But normally pr’s from dependabot always fails on test.

Some do. Some don’t. I can’t stand not knowing why! 😃

0reactions
tigcommented, Nov 4, 2022

I’ve not seen this, except when I’m using the clipboard in another app while tests are running. Closing for now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Unit test fails when running all, but passes when ...
I have had this issue before and it boiled down to two tests running at the same time using some shared piece of...
Read more >
Flaky tests resolving using Test Repetitions in Xcode
Flaky tests can be resolved using test repetitions and several best practices when writing tests and running tests locally.
Read more >
Tests that sometimes fail
Unit tests also sometimes fail because of not cleaning up state properly, which only breaks things when tests run in a very specific...
Read more >
Why your tests may pass locally but fail in Jenkins
Symptom: Tests pass locally when run in a certain order, but fail in Jenkins when run in a different order (or tests pass/fail...
Read more >
How to Fix Flaky Tests - Semaphore CI
A test that intermittently fails for no apparent reason — or works in your local machine and fails with continuous integration — is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found