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.

Starting having MainLoopTests.InvokeLeakTest failure after push develop branch to my fork .

See original GitHub issue
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed Terminal.Gui.Core.MainLoopTests.InvokeLeakTest [1 s]
  Error Message:
[xUnit.net 00:01:04.81]     Terminal.Gui.Core.MainLoopTests.InvokeLeakTest [FAIL]
   System.TimeoutException : Timeout: Increment lost. tbCounter (41) didn't change after waiting 500 ms. Failed to reach 10000 on pass 1
  Stack Trace:
     at Terminal.Gui.Core.MainLoopTests.RunTest(Random r, TextField tf, Int32 numPasses, Int32 numIncrements, Int32 pollMs) in /home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/MainLoopTests.cs:line 556
   at Terminal.Gui.Core.MainLoopTests.<>c__DisplayClass24_0.<InvokeLeakTest>b__0() in /home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/MainLoopTests.cs:line 577
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Terminal.Gui.Core.MainLoopTests.InvokeLeakTest() in /home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/MainLoopTests.cs:line 582
--- End of stack trace from previous location ---

Attachments:
  /home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/TestResults/5774b41c-7d1a-461a-a399-f2edfe5328aa/coverage.opencover.xml
Failed!  - Failed:     1, Passed:   873, Skipped:     0, Total:   874, Duration: 1 m 9 s - /home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/bin/Debug/net6.0/UnitTests.dll (net6.0)
     4>Done Building Project "/home/runner/work/Terminal.Gui/Terminal.Gui/UnitTests/UnitTests.csproj" (VSTest target(s)) -- FAILED.
     1>Done Building Project "/home/runner/work/Terminal.Gui/Terminal.Gui/Terminal.sln" (VSTest target(s)) -- FAILED.

Build FAILED.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:01:19.40
Error: Process completed with exit code 1.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
montekarloscommented, Sep 16, 2022

My suggestion would be to change the test to

volatile static int tbCounter = 0;
static ManualResetEventSlim _wakeUp = new ManualResetEventSlim (false);

private static void Launch (Random r, TextField tf, int target)
{
	Task.Run (() => {
		Thread.Sleep (r.Next (2, 4));
		Application.MainLoop.Invoke (() => {
			tf.Text = $"index{r.Next ()}";
			Interlocked.Increment (ref tbCounter);
			if (target == tbCounter) {
				// On last increment wake up the check
				_wakeUp.Set ();
			}
		});
	});
}

private static void RunTest (Random r, TextField tf, int numPasses, int numIncrements, int pollMs)
{
	for (int j = 0; j < numPasses; j++) {

		_wakeUp.Reset ();
		for (var i = 0; i < numIncrements; i++) {
			Launch (r, tf, (j + 1) * numIncrements);
		}

		
		while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
		{
			var tbNow = tbCounter;
			_wakeUp.Wait (pollMs);
			if (tbCounter == tbNow) {
				// No change after wait: Idle handlers added via Application.MainLoop.Invoke have gone missing
				Application.MainLoop.Invoke (() => Application.RequestStop ());
				throw new TimeoutException (
					$"Timeout: Increment lost. tbCounter ({tbCounter}) didn't " +
					$"change after waiting {pollMs} ms. Failed to reach {(j + 1) * numIncrements} on pass {j + 1}");
			}
		};
	}
	Application.MainLoop.Invoke (() => Application.RequestStop ());
}

[Fact]
[AutoInitShutdown]
public async Task InvokeLeakTest ()
{
	Random r = new ();
	TextField tf = new ();
	Application.Top.Add (tf);

	const int numPasses = 10;
	const int numIncrements = 10000;
	const int pollMs = 20000;

	var task = Task.Run (() => RunTest (r, tf, numPasses, numIncrements, pollMs));

	// blocks here until the RequestStop is processed at the end of the test
	Application.Run ();

	await task; // Propagate exception if any occurred

	Assert.Equal ((numIncrements * numPasses), tbCounter);
}

This gives a much longer timeout for slow build systems but is still ‘fast’ locally

It’s been my experience that it’s quite difficult to unit test non deterministic threading behaviour effectively

Note I haven’t tested if this reproduces the original bug prefix

0reactions
BDispcommented, Sep 15, 2022

I think it’s already fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I safely get my local git branch back into my fork?
But don't get into the habit of just slapping on --force any time git push fails with some error message you don't understand....
Read more >
Committing changes to a pull request branch created from ...
To resolve the error, you must clone the fork in a different directory. Navigate into your new cloned repository. cd FORK-OF-THE-REPOSITORY. Switch branches...
Read more >
Git Forks And Upstreams: How-to and a cool tip
Git upstreams are key to keeping track of project changes. Our tutorial will get you started using git upstream and forks to maintain...
Read more >
Git rebase and force push
Fail fast testing ... Git imports all the commits submitted to your target branch after you ... You have the Developer role for...
Read more >
Updating your forked repository on GitHub
An error occurred while retrieving sharing information. ... from the original repo into your local clone, and then push those changes to your...
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