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

Missing using instruction in Exclude and Lead #649

Closed
2 tasks done
Orace opened this issue Nov 6, 2019 · 9 comments · Fixed by #673
Closed
2 tasks done

Missing using instruction in Exclude and Lead #649

Orace opened this issue Nov 6, 2019 · 9 comments · Fixed by #673
Labels

Comments

@Orace
Copy link
Contributor

Orace commented Nov 6, 2019

Here the list of not disposed enumerators
Unit test should be added for it (maybe we can do a generic test like NullArgumentTest).

  • MoreLinq\Exclude.cs:48
  • MoreLinq\Lead.cs:68
    SkipUntil

We should have test for them

@atifaziz
Copy link
Member

atifaziz commented Nov 6, 2019

I somehow doubted the list is long. Let's take your first example of line 70 of Backsert:

using var e = first.CountDown(index, ValueTuple.Create).GetEnumerator();

How's the enumerator not being disposed? I see a using that has the scope of the method.

maybe we can do a generic test like NullArgumentTest

This is tricky but if you have ideas on how then I am listening. Meanwhile, we have TestingSequence that should be used to help with checking for proper disposal. You can see this is used in tests for Backsert:

public IEnumerable<int> Backsert(int[] seq1, int index, int[] seq2)
{
using (var test1 = seq1.AsTestingSequence())
using (var test2 = seq2.AsTestingSequence())
{
return test1.Backsert(test2, index).ToArray();
}
}

Now, technically, if you remove the using in the Backsert then the tests should break. What's disturbing is that they don't and so you've highlighted another issue!

As yet another issue, Pairwise is missing the test:

[Test]
public void PairwiseWideSourceSequence()
{
var result = new[] { "a", "b", "c", "d" }.Pairwise((x, y) => x + y);
result.AssertSequenceEqual("ab", "bc", "cd");
}

So you've highlighted new issues by bringing up a potential non-issue. 😄

@Orace
Copy link
Contributor Author

Orace commented Nov 6, 2019

Indead Reasharper doesn't handle the new inline using.
I will update the list.

@atifaziz atifaziz changed the title Instance of IEnumerator are never disposed Enumerator never disposed Nov 6, 2019
@atifaziz atifaziz changed the title Enumerator never disposed Some forget to dispose source enumerator Nov 6, 2019
@Orace Orace changed the title Some forget to dispose source enumerator Some methods forget to dispose source enumerator Nov 7, 2019
@Orace
Copy link
Contributor Author

Orace commented Nov 7, 2019

SkipUntil has to be fixed and tested too. (Found by a Monkey : #663 )

@atifaziz
Copy link
Member

atifaziz commented Nov 9, 2019

It seems that I have introduced some leaks in 3d44f73 cdc6f76 from PR #621. It seems that there wasn't enough test coverage to make that refactoring confidently. I wrongly assumed that if no tests broke then no leakage was introduced. Either 3d44f73 cdc6f76 should be reverted or it requires a second and closer (eyeball) review. Adding code coverage is becoming crucial going forward.

@Orace
Copy link
Contributor Author

Orace commented Nov 9, 2019

I'm not sure it's 3d44f73 since it's about use of ??=
Maybe this one: cdc6f76

@Orace
Copy link
Contributor Author

Orace commented Nov 9, 2019

I read the full diff and find two missing using.
Turn out it was for Exclude and Lead

@atifaziz
Copy link
Member

atifaziz commented Nov 9, 2019

I'm not sure it's 3d44f73 since it's about use of ??=
Maybe this one: cdc6f76

You're right. 🤦‍♂ I copied the wrong commit hash.

@Orace
Copy link
Contributor Author

Orace commented Nov 9, 2019

SkipUntil dispose properly its enumerator.

@atifaziz
Copy link
Member

atifaziz commented Nov 9, 2019

I read the full diff and find two missing using.
Turn out it was for Exclude and Lead

Hey, thanks a ton for reviewing the diff! ⭐️

@Orace Orace changed the title Some methods don't dispose enumerator Bug: Missing using instruction in Exclude and Lead Nov 9, 2019
@atifaziz atifaziz added the bug label Nov 9, 2019
@atifaziz atifaziz changed the title Bug: Missing using instruction in Exclude and Lead Missing using instruction in Exclude and Lead Nov 9, 2019
atifaziz pushed a commit that referenced this issue Nov 9, 2019
This is a squashed merge or PR #673 that closes #649.

It fixes mistakes made in commit "Replace using statements with
declarations" (hash cdc6f76)
as part of PR #622.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants