Skip to content
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

Don't allow duplicate formats in configuration. #684

Merged
merged 2 commits into from
Aug 26, 2018

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #683

ConcurrentBag<T> allows duplicates which we do not want. I locked a HashSet<T> since there is no ConcurrentSet<T> type in the .NET Framework.

@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Aug 24, 2018
@codecov
Copy link

codecov bot commented Aug 24, 2018

Codecov Report

Merging #684 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   89.35%   89.35%   +<.01%     
==========================================
  Files         878      878              
  Lines       39225    39237      +12     
  Branches     2557     2558       +1     
==========================================
+ Hits        35048    35060      +12     
  Misses       3482     3482              
  Partials      695      695
Impacted Files Coverage Δ
src/ImageSharp/Formats/ImageFormatManager.cs 82.35% <100%> (+1.5%) ⬆️
tests/ImageSharp.Tests/ConfigurationTests.cs 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d990a7c...1c72e61. Read the comment docs.

@tzachshabtay
Copy link

In my project I used ConcurrentDictionary with a byte value which I ignore: https://github.com/tzachshabtay/MonoAGS/blob/master/Source/Engine/AGS.Engine/Misc/Collection/AGSConcurrentHashSet.cs

I don't know if it's better than simply locking the hashset.

@@ -96,5 +92,13 @@ public void AddFormatCallsConfig()

provider.Verify(x => x.Configure(config));
}

[Fact]
public void DefaultConfigurationHasCorrectFormatCount()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we also need to test that we don't allow adding duplicates?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll add a simple one.

@JimBobSquarePants
Copy link
Member Author

JimBobSquarePants commented Aug 24, 2018

@tzachshabtay I think I might do that actually; the lock felt ugly. Thanks!

Update, the dictionary is breaking two tests as I'd need to implement IEquatable<IImageFormat> for the formats. That's too much for me to bother with so I'm gonna leave it as-is.

@antonfirsov
Copy link
Member

Why do we even try adding duplicates? Maybe we should just remove that part of code.

@JimBobSquarePants
Copy link
Member Author

We call it when adding both encoders and decoders since they are independent operations

@JimBobSquarePants JimBobSquarePants merged commit 301c2ce into master Aug 26, 2018
@JimBobSquarePants JimBobSquarePants deleted the js/DuplicateFormats branch August 26, 2018 09:35
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
Don't allow duplicate formats in configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants