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

Fix multi-result behavior across all versions of PowerShell (fixes CI UT's on all platforms) #199

Merged
merged 5 commits into from
May 30, 2020

Conversation

HowardWolosky
Copy link
Member

@HowardWolosky HowardWolosky commented May 29, 2020

Tests were failing on Mac and Linux, but not Windows (recent test run). That's because Windows CI was running against PoSh 5.x while Linux and Mac were running on PoSh 7.x.

There's a slight difference in behavior for how those two treat arrays.

The real root cause for this was the behavior of Invoke-GHRestMethodMultipleResult. When creating $finalResult, it was always blindly adding the result to the existing array:

$finalResult = @()

...
$finalResult += $result.result

Oddly enough, this created a difference in behavior between PowerShell versions when making the result an array on the caller side. Now I ensure that I don't add anything to $finalResult unless there's actually a value. With that change, we can now be sure that when we grab the result as an array, it'll be appropriately empty or populated (and not populated with a single $null entry, thus making Count 1, erroneously).

I removed the attempt to force the results to be an array, because this is pointless. PowerShell will always unwrap an array of 0 or 1 in a return result. If you want to ensure that a result is always an array, you have to wrap the result in an object or you have to do wrap the result in an array on the caller side.

# Ensure we're always returning our results as an array, even if there is a single result.
return @($finalResult)

I also normalized some naming in all of the tests, so that when we're getting back a singular result (by querying for a specific item) that we use a singular variable name, and a plural variable name otherwise.

With this change, we should now be passing CI on all OS platforms and across PowerShell 4+.

Resolves #198

…lved

Tests are failing remotely on Linux but not locally.
Disabling for now until this can be investigated and resolved, so that
we can still depend at least on the Windows CI build in the interim.

Recent run with Linux UT failures:
https://dev.azure.com/ms/PowerShellForGitHub/_build/results?buildId=83887&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb
@HowardWolosky HowardWolosky added the build Changes related to the build infrastructure for the project. label May 29, 2020
@HowardWolosky
Copy link
Member Author

Need to see if the issue is limited to just Linux, or if mac UT's are failing similarly. So, we'll run once with just Linux disabled. If mac has similar failures, then we'll just disable UT's in both for the time being and track figuring out what's going on via #198.

@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky changed the title Temporarily disable Linux in CI until unexpected UT failures are resolved Fix multi-result behavior across all versions of PowerShell (fixes CI UT's on all platforms) May 30, 2020
@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky added the bug This relates to a bug in the existing module. label May 30, 2020
@HowardWolosky HowardWolosky merged commit bcd0a56 into microsoft:master May 30, 2020
@HowardWolosky HowardWolosky deleted the ciDisableLinuxAndMac branch May 30, 2020 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This relates to a bug in the existing module. build Changes related to the build infrastructure for the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate UT failures happening on Linux/mac in CI build
1 participant