Test randomly hangs in CI #727
-
Hi, I've been using BUnit for a few months now and things are mostly going great. However, I'm now facing a weird issue that's hard to understand. One of my tests seems to sometimes not be able to finish executing. It seems to hang on WaitForState or WaitForAssertionCalls. public void CliquerSurResultat_FermeRecherche() {
AfficherEdition();
RechercheApi.RechercherProjet(default).ReturnsForAnyArgs(new RechercheAvecProfilResponse() {
Items = { new() { Code = "X" } }
});
Edition.WaitForState(() => Edition.EditionSpinner() == null);
Edition.Projet().Click();
Recherche.WaitForState(() => Recherche.Resultats().Count > 0);
Recherche.Resultats()[0].Click();
Recherche.WaitForAssertion(() => Recherche.EstFermee());
} What the test does is as follows : We have a lot of these kind of tests and I can't see anything special with it but for some reason, only this one seems to be causing deadlocks or something of that nature when executing in CI. I have been able to reproduce it using the dotnet.exe CLI with a powershell script that runs the tests in a loop until it fails due to
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
That might be related to #710 . Can you try the latest preview release? See #209 how to get the latest preview |
Beta Was this translation helpful? Give feedback.
-
I tried to run it locally, and this is the exception I received after a few iteractions: Test Run Aborted with error System.Exception: One or more errors occurred.
---> System.Exception: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Exception: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
at System.Net.Sockets.NetworkStream.ReadByte()
at System.IO.BinaryReader.Read7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable()
at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action`1 errorHandler, CancellationToken cancellationToken)
--- End of inner exception stack trace ---.
The active Test Run was aborted because the host process exited unexpectedly. Please inspect the call stack above, if available, to get more information about where the exception originated from.
The test running when the crash occurred:
FeuilleTemps.Interface.Pages.Horodateur.Edition.RechercheTests.CliquerSurResultat_FermeRecherche
This test may, or may not be the source of the crash.
Nope, inspected the memory dump and this is indeed related to #577. |
Beta Was this translation helpful? Give feedback.
-
Took a more detailed look at you test code. In protected IRenderedComponent<FeuilleTempsEdition> Edition => Horodateur.FindComponent<FeuilleTempsEdition>(); You are calling I changed the top of protected IRenderedComponent<FeuilleTempsEdition> Edition()
=> Horodateur.FindComponent<FeuilleTempsEdition>();
protected IGestionChronometre GestionChronometre { get; private set; }
protected IRenderedComponent<ModalConfirmerQuitterEdition> ModalConfirmerQuitterEdition() =>
Horodateur.FindComponent<ModalConfirmerQuitterEdition>();
protected IRenderedComponent<FenetreRecherche> Recherche()
=> Horodateur.FindComponent<FenetreRecherche>(); and the test to this: [TestMethod("Cliquer sur un résultat ferme le panneau de recherche")]
public void CliquerSurResultat_FermeRecherche() {
AfficherEdition();
RechercheApi.RechercherProjet(default).ReturnsForAnyArgs(new RechercheAvecProfilResponse() {
Items = { new() { Code = "X" } }
});
var edition = Edition();
var recherche = Recherche();
edition.WaitForState(() => edition.EditionSpinner() == null);
edition.Projet().Click();
recherche.WaitForState(() => recherche.Resultats().Count > 0);
recherche.Resultats()[0].Click();
recherche.WaitForAssertion(() => recherche.EstFermee());
} And now the test seems to be running without a problem (current at 75 iterations without fail, before it only lasted three iterations). So that does solve your particular problem, but besides that, we do have a deadlock possibility if people use Thanks for the sample code, it will make it much easier for me to create a fix. |
Beta Was this translation helpful? Give feedback.
Took a more detailed look at you test code.
In
EditerTestsBase
you have two properties,Edition
andRecherche
, that you use multiple times in your test. However, because you write them like this:You are calling
FindComponent
everytime you access the property, which is not only wasteful, but probably not what you want.I changed the top of
EditerTestsBase
to this: