Skip to content

Dialog: Revert #8964 (Fix possible deadlock)#9030

Merged
ScarletKuro merged 5 commits intoMudBlazor:devfrom
danielchalmers:dialog-timing-regression-p3
May 25, 2024
Merged

Dialog: Revert #8964 (Fix possible deadlock)#9030
ScarletKuro merged 5 commits intoMudBlazor:devfrom
danielchalmers:dialog-timing-regression-p3

Conversation

@danielchalmers
Copy link
Member

@danielchalmers danielchalmers commented May 21, 2024

Description

Reverts #8964

Caused timing issues in my app's tests. I tried to replicate it in the MudBlazor tests but it won't compile.

How Has This Been Tested?

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label May 21, 2024
@henon
Copy link
Contributor

henon commented May 21, 2024

@danielchalmers what does that mean Revert fix to possible deadlock. Does it mean after the revert it might deadlock again? Or does it mean we revert because it possibly deadlocks now i.e. Revert fix due to possible deadlock?

Ah nvm, I got it, it means it might deadlock again after the revert.

@henon henon changed the title Dialog: Revert fix to possible deadlock Dialog: Revert fix of possible deadlock due to other timing issues May 21, 2024
@codecov
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.62%. Comparing base (28bc599) to head (fab65d3).
Report is 1103 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9030      +/-   ##
==========================================
+ Coverage   89.82%   90.62%   +0.79%     
==========================================
  Files         412      398      -14     
  Lines       11878    12375     +497     
  Branches     2364     2403      +39     
==========================================
+ Hits        10670    11215     +545     
+ Misses        681      621      -60     
- Partials      527      539      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ScarletKuro
Copy link
Member

I will investigate this later with daniels project etc

@danielchalmers
Copy link
Member Author

I will investigate this later with daniels project etc

@ScarletKuro I don't think I translated the tests properly because they are working on MudBlazor. Will try to get them failing later (lol). But yeah in the meantime my project still fails with p3 package. Requires MAUI

@ScarletKuro ScarletKuro self-assigned this May 23, 2024
@danielchalmers
Copy link
Member Author

@ScarletKuro Struggling to get the test failing on the MB test suite despite the fact that it decisively fails on my project with an update from p2 to p3.

@danielchalmers danielchalmers marked this pull request as ready for review May 24, 2024 23:48
@ScarletKuro
Copy link
Member

I haven't worked with bUnit's Render(Razor_Syntax) API; it feels like it's doing a bad job of tracking the DOM changes. However, when I slightly modified your tests:

Note test
[Fact]
public void Note()
{
  var category = new DataPointCategory
  {
  	Guid = Guid.NewGuid(),
  	Type = PointType.Note,
  };

  var day = Day.Create(new(2024, 01, 01));
  var point = DataPoint.Create(day, category);
  point.Text = "Hello world";
  
  var layout = Render(
  	@<MainLayout>
  		<Body>
  			<DataPointView Point="point" />
  		</Body>
  	</MainLayout>);

  var cut = () => layout.FindComponent<DataPointView>();

  cut().Find(".mud-link").Click();

  var noteEditor = () => layout.FindComponent<EditNoteDialog>();
  noteEditor().Find("textarea").Input("123");
  layout.Find(".submit-button").Click();

  point.Text.Should().Be("123");

  cut().Find(".mud-link").Click();

  noteEditor().Find("textarea").Input("EXTRA TEXT THAT WILL BE DISCARDED");
  layout.Find(".cancel-button").Click();

  point.Text.Should().Be("123");
}

and

MedicationEditDose test
[Fact]
public void MedicationEditDose()
{
  var category = new DataPointCategory
  {
  	Guid = Guid.NewGuid(),
  	Type = PointType.Medication,
  	MedicationUnit = "oz",
  	MedicationDose = 11,
  };

  var day = Day.Create(new(2024, 01, 01));
  var point = DataPoint.Create(day, category);
  point.Text = "Hello world";
  point.MedicationDose = 22;

  var layout = Render(
     @<MainLayout>
  		<Body>
  			<DataPointView Point="point" />
  		</Body>
  	</MainLayout>);

  var cut = () => layout.FindComponent<DataPointView>();

  // Initial state.
  point.Bool.Should().Be(null);
  cut().FindAll(".mud-toggle-item-selected").Count.Should().Be(0);

  // Change dose to empty via dialog.
  cut().Find(".mud-link").Click();
  var doseEditor = () => layout.FindComponent<EditDoseDialog>();
  doseEditor().Find("input").Input("");
  layout.Find(".submit-button").Click();

  // Empty dose resets to default and selects No.
  point.MedicationDose.Should().Be(point.Category.MedicationDose);
  cut().FindAll(".mud-toggle-item")[0].ClassList.Should().Contain("mud-toggle-item-selected");

  // Change dose via dialog.
  cut().Find(".mud-link").Click();
  doseEditor().Find("input").Input("99");
  layout.Find(".submit-button").Click();

  // Submitting dose is the same as Yes.
  point.MedicationDose.Should().Be(99);
  cut().FindAll(".mud-toggle-item")[1].ClassList.Should().Contain("mud-toggle-item-selected");

  // Cancel dialog.
  cut().Find(".mud-link").Click();
  doseEditor().Find("input").Input("88");
  layout.Find(".cancel-button").Click();

  // Same as before
  point.MedicationDose.Should().Be(99);
  cut().FindAll(".mud-toggle-item")[1].ClassList.Should().Contain("mud-toggle-item-selected");
}

It works as expected.

@ScarletKuro
Copy link
Member

By the way, if you ask why it worked before, I don't know, as it requires understanding how bUnit works internally. This isn't the first time this has happened. For example, when a Task method becomes truly asynchronous:
async Task SomeTask => await Task.CompletedTask vs async Task SomeTask => await Task.Delay(x), the Find methods start to behave differently.

@danielchalmers
Copy link
Member Author

Thanks for all the help @ScarletKuro. I opened a discussion with bUnit to confirm bUnit-dev/bUnit#1470

@ScarletKuro
Copy link
Member

@danielchalmers another similar thing happened when you asked for this change: #8203. It doesn't have anything to do with the async aspect, but rather with the render counts. However, we also had to replace all FindAll with lambdas, even though it turns out that FindAll has an enableAutoRefresh overload which is false by default. But we had already begun utilizing the lambdas so I don't want to change that.

@danielchalmers
Copy link
Member Author

@danielchalmers another similar thing happened when you asked for this change: #8203. It doesn't have anything to do with the async aspect, but rather with the render counts. However, we also had to replace all FindAll with lambdas, even though it turns out that FindAll has an enableAutoRefresh overload which is false by default. But we had already begun utilizing the lambdas so I don't want to change that.

@ScarletKuro Great, I'm trying to learn more about this area so thank you again!

@ScarletKuro
Copy link
Member

ScarletKuro commented May 25, 2024

Ah I might be wrong. I was running the test individually so it works, but it is failing when you run all the tests at same time and it does with my changes too

@ScarletKuro ScarletKuro reopened this May 25, 2024
@ScarletKuro ScarletKuro changed the title Dialog: Revert fix of possible deadlock due to other timing issues Dialog: Revert #8964 May 25, 2024
@ScarletKuro ScarletKuro changed the title Dialog: Revert #8964 Dialog: Revert #8964 (Fix possible deadlock) May 25, 2024
@ScarletKuro
Copy link
Member

ScarletKuro commented May 25, 2024

I'm reverting this. The reason is that the suggested test improvement turned out to not work. While it's still weird that the tests pass when you run them individually but fail when you run them in batch (seems like it's some xUnit thing), my time is becoming more limited each day and I don't want to invest too much time in finding the root cause. However, I also don't want people's tests to be broken. This change was made to align the code with Blazored/Modal, and it was something that Microsoft recommended in their async guide. But in fact, nobody really complained about any deadlock in the dialog. Additionally, in the future, the dialog is most likely going to undergo some kind of rework.

@ScarletKuro ScarletKuro merged commit 6107840 into MudBlazor:dev May 25, 2024
@danielchalmers danielchalmers added regression Previously worked and now doesn't and removed accidental break labels Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended regression Previously worked and now doesn't

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants