Skip to content

Fix Exception in list static filter index assumptions#1120

Open
jcummings2 wants to merge 8 commits into
reactivemarbles:mainfrom
jcummings2:fix-removekey-list-static-filter-index-assumptions
Open

Fix Exception in list static filter index assumptions#1120
jcummings2 wants to merge 8 commits into
reactivemarbles:mainfrom
jcummings2:fix-removekey-list-static-filter-index-assumptions

Conversation

@jcummings2

Copy link
Copy Markdown
Contributor

See #1119

public void Dispose() => _cleanup.Dispose();

[Fact]
public void Add()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test names should be a little more descriptive. Ideally, the pattern is "UnitUnderTest_Scenario_ExpectedOutcome", but that's certainly not followed everywhere, so at minimum, we just want to see some description of either "Scenario" or "ExpectedOutcome" in the name. Just saying "Add", "Refresh", etc. doesn't tell me anything about what we're intending to test here. Could be as simple as "KeyIsRemoved".

@jcummings2 jcummings2 Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't discern the patten used in this code base so I went very basic. I can improve the name(s). I'm not sure what you would want for "UnitUnderTest" in the pattern.

_cleanup.Add(
_source.Connect()
.RemoveKey()
.Filter(x => x.Age < average)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the test fixture for "RemoveKey", the only thing that should be getting tested is .RemoveKey(), What you're REALLY trying to test for here is behavior in .Filter(), specifically, .Filter()'s ability to support missing indexes. That belongs in the appropriate "Filter" fixture.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What I was actually trying to demonstrate was what series of calls would lead to the error. This test is really just a step indicating it wasn't the problem. Filter() itself is tested more thoroughly in all the Filter* classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are you trying to say you want this test removed?

// A Replace might have a negative CurrentIndex from a Refresh in RemoveKeyEnumerator
if (currentIndex < 0)
{
// this code mimics the previous logic

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment doesn't belong here. Useful for the PR, sure, but just pulling up and reading this comment, as-is begs the question "What previous logic?". The comment above clarifying that CurrentIndex can be negative does plenty to tell us what's going on here: we don't have the index, so we've got to look it up.

var itemState = upstreamItemsStates[change.Item.CurrentIndex];
upstreamItemsStates[change.Item.CurrentIndex] = (
var currentIndex = change.Item.CurrentIndex;
// A Replace might have a negative CurrentIndex from a Refresh in RemoveKeyEnumerator

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably not even the only scenario. Boy do I hate working inside the old "list" code.

@jcummings2

Copy link
Copy Markdown
Contributor Author

I updated test names and removed the extraneous comment per your feedback. Let me know if those names need further tweaking.

I also added another test that moves the RemoveKey() call to just before the bind. This new test passes even with the old code as it turns out.

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.

2 participants