Skip to content

Conversation

@SimonCropp
Copy link
Contributor

attempt to replicate #593 (comment)

Copilot AI review requested due to automatic review settings January 12, 2026 23:14
@SimonCropp SimonCropp requested a review from a team as a code owner January 12, 2026 23:14
@SimonCropp SimonCropp marked this pull request as draft January 12, 2026 23:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a test case to verify that reading empty and null PLP (Partially Length-Prefixed) strings asynchronously does not throw an ArgumentNullException when using the new async behavior. The test is a regression test for issue #593, which originally reported severe performance problems when reading large binary data asynchronously.

Changes:

  • Added a new async test ReadEmptyAndNullPlpStringsAsyncWithNewBehavior that validates reading NULL and empty string values from VARCHAR(MAX), NVARCHAR(MAX), and TEXT columns
  • The test disables compatibility mode to use the new async behavior via the UseCompatibilityAsyncBehaviour switch

Comment on lines +1098 to +1102
using (var switchHelper = new SwitchesHelper())
{
originalSwitchValue = switchHelper.UseCompatibilityAsyncBehaviour;
switchHelper.UseCompatibilityAsyncBehaviour = false;
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The SwitchesHelper usage pattern is incorrect. The helper is being disposed at line 1102 before the actual test runs, which means the UseCompatibilityAsyncBehaviour switch will be restored to its original value before the test executes.

The correct pattern is to keep the SwitchesHelper alive for the entire scope where you need the modified switch value. The helper should be created at the beginning of the try block and only disposed after all test operations that depend on the switch value are complete.

Looking at other tests in this file (e.g., CheckNullRowVersionIsDBNull at line 270), the pattern should be:

  • Create the SwitchesHelper at the start of the try block
  • Set the switch value
  • Run all test operations
  • The helper will be automatically disposed at the end of the using block, restoring the original value

Additionally, lines 1185-1188 attempt to restore the switch value manually, but this is unnecessary and incorrect since the Dispose method of SwitchesHelper already restores all original values automatically.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +1183 to +1189
if (originalSwitchValue.HasValue)
{
using (var switchHelper = new SwitchesHelper())
{
switchHelper.UseCompatibilityAsyncBehaviour = originalSwitchValue;
}
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The manual restoration of the switch value is unnecessary and incorrect. The SwitchesHelper class automatically restores all original switch values in its Dispose method. This entire block (lines 1183-1189) should be removed, as it serves no purpose and is based on a misunderstanding of how the helper works.

Furthermore, the variable 'originalSwitchValue' at line 1093 is only used in this incorrect restoration logic and can also be removed.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

@cheenamalhotra cheenamalhotra added the Area\Tests Issues that are targeted to tests or test projects label Jan 13, 2026
@SimonCropp
Copy link
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread

@SimonCropp
Copy link
Contributor Author

@cheenamalhotra where should i see the PRs i request from copilot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Tests Issues that are targeted to tests or test projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants