-
Notifications
You must be signed in to change notification settings - Fork 696
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
TreeView
sometimes causing unit test failure
#2944
Comments
…s unit test error.
Re-opening because I just got this on v2_develop. #2945 does not seem to fix this: |
Murmur, muble, muble, grrrr, mumble, mumble. 😠 |
…s unit test error.
@BDisp I know you spent a ton of time on this (and I just noticed you just tried again after typing all this up!!!). I just noticed something and am currently investigating. Would love to know your thoughts. In this test the comments say some things that I don't think are right: [Fact]
public void Changing_One_Default_Reference_Also_Change_All_References_But_Not_A_Instance_Reference ()
{
// Make two local attributes, and grab Attribute.Default, which is a reference to a static.
Attribute attr1 = Attribute.Default;
Attribute attr2 = Attribute.Default;
// Make one local attributes, and grab Attribute(), which is a reference to a singleton.
Attribute attr3 = new Attribute (); // instance
// Assert the starting state that is expected
Assert.Equal (ColorName.White, attr1.Foreground.ColorName);
Assert.Equal (ColorName.White, attr2.Foreground.ColorName);
Assert.Equal (ColorName.White, Attribute.Default.Foreground.ColorName);
Assert.Equal (ColorName.White, attr3.Foreground.ColorName);
// Now set Foreground.ColorName to ColorName.Blue on one of our local attributes
attr1.Foreground.ColorName = ColorName.Blue;
// Assert the newly-expected case
// The last two assertions will fail, because we have actually modified a singleton
Assert.Equal (ColorName.Blue, attr1.Foreground.ColorName);
Assert.Equal (ColorName.Blue, attr2.Foreground.ColorName);
Assert.Equal (ColorName.Blue, Attribute.Default.Foreground.ColorName);
Assert.Equal (ColorName.White, attr3.Foreground.ColorName);
// Now set Foreground.ColorName to ColorName.Red on the singleton of our local attributes
attr3.Foreground.ColorName = ColorName.Red;
// Assert the newly-expected case
// The assertions will not fail, because we have actually modified a singleton
Assert.Equal (ColorName.Blue, attr1.Foreground.ColorName);
Assert.Equal (ColorName.Blue, attr2.Foreground.ColorName);
Assert.Equal (ColorName.Blue, Attribute.Default.Foreground.ColorName);
Assert.Equal (ColorName.Red, attr3.Foreground.ColorName);
// Now set Foreground.ColorName to ColorName.White on the static of our local attributes
// This also avoids errors on others unit test when the default is changed
Attribute.Default.Foreground.ColorName = ColorName.White;
// Assert the newly-expected case
// The assertions will not fail, because we have actually modified the static default reference
Assert.Equal (ColorName.White, attr1.Foreground.ColorName);
Assert.Equal (ColorName.White, attr2.Foreground.ColorName);
Assert.Equal (ColorName.White, Attribute.Default.Foreground.ColorName);
Assert.Equal (ColorName.Red, attr3.Foreground.ColorName);
} Specifically: // Make one local attributes, and grab Attribute(), which is a reference to a singleton.
Attribute attr3 = new Attribute (); // instance Here, I have been able to reproduce the [Fact]
public void Small_Repro_of_TreeViewTests_TestTreeViewColor ()
{
Assert.Equal (Color.White, Attribute.Default.Foreground.ColorName);
Attribute defaultAttribute = Attribute.Default;
Assert.Equal (Color.White, defaultAttribute.Foreground.ColorName);
Assert.True (Equals (defaultAttribute, Attribute.Default));
defaultAttribute = new Attribute (Color.Red, Color.Green);
Assert.Equal (Color.Red, defaultAttribute.Foreground.ColorName);
Assert.Equal (Color.White, Attribute.Default.Foreground.ColorName);
defaultAttribute = Attribute.Default;
defaultAttribute.Foreground.ColorName = Color.Blue;
Assert.Equal (Color.Blue, defaultAttribute.Foreground.ColorName);
// This fails because `defaultAttribute.Foreground.ColorName = Color.Blue` changes
// the internal state of the `static readonly Attribute Default` field.
Assert.Equal (Color.White, Attribute.Default.Foreground.ColorName);
} This fails because The current impl of [JsonConverter (typeof (AttributeJsonConverter))]
public readonly struct Attribute : IEquatable<Attribute> {
/// <summary>
/// Default empty attribute.
/// </summary>
public static readonly Attribute Default = new Attribute (Color.White, Color.Black); With this I (I think it was me) made it so The A fix would be: [JsonConverter (typeof (AttributeJsonConverter))]
public readonly struct Attribute : IEquatable<Attribute> {
/// <summary>
/// Default empty attribute.
/// </summary>
public static Attribute Default => new Attribute (Color.White, Color.Black); This makes [JsonConverter (typeof (AttributeJsonConverter))]
public readonly struct Attribute : IEquatable<Attribute> {
/// <summary>
/// Default empty attribute.
/// </summary>
public static Attribute Default {
get {
return new Attribute (Color.White, Color.Black);
}
} With this, any reference to However, while I think we should make this change (and I'm confident it fixes the TreeView testcase), I still think we have a problem: The fact that I can do Therefore, I propose we
New PR soon! |
It's bad, it's an new instance sorry. Only the Default is a singleton because it's static. Or like this: [JsonConverter (typeof (AttributeJsonConverter))]
public readonly struct Attribute : IEquatable<Attribute> {
/// <summary>
/// Default empty attribute.
/// </summary>
public static Attribute Default {
get => new Attribute (Color.White, Color.Black);
} I'll close the #3162, right? |
Sí. |
…ibute` and `Color` are read only value types (#3163) * Removed resharper settings from editorconfig * Initial work in progress * API doc * API doc * initial commit * Fixed color and attribute issues * Made Color a value type (readonly struct) etc... * Removed stuff from other PR * Ensured Colors.ColorScheme has private setter * oops * oops 2 * Code cleanup * Code cleanup * oops 4 * Reverted Attrivte.Default to be readonly static * Fixed [Fact] [AutoInitShutdown]
TreeView
sometimes causing unit test failure
I think it may be:
|
….Base`, etc..., Fixes intermittent `TreeView` unit test failures (#3175) * Removed resharper settings from editorconfig * Moved ColorScheme to ColorScheme.cs * Moved ColorScheme to ColorScheme.cs * Potential fix. PlatformColor was not being set by FakeDriver correctly. * Made ColorScheme effectively readonly * Removed Color.Base etc... Updated API docs.
I have not seen this in 5 days! I declare victory. 99% sure it was |
Originally posted by @BDisp in #2941 (comment)
The text was updated successfully, but these errors were encountered: