From f406cc5b8ab9eb0229c1834c3266060d8fc1ceb1 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sat, 18 Jul 2020 12:06:17 -0700 Subject: [PATCH] Attempting to increase reliability of some Pester tests (#265) We're seeing some inconsistent failures in some of the Pester tests. The hypothesis is that GitHub may need a little bit more time after the creation of objects before performing certain operations on them (like renaming repos), or may need more time after deleting them before it will successfully return a 404 on a successive Get request. I have added a number of `Start-Sleep`'s throughout the test codebase wherever we've encountered inconsistent failures, and that appears to have resolved the problem. We may need to continue to do more of these if additional ones pop up. The duration of the sleep itself is controlled by `$script:defaultSleepSecondsForReliability` which is defined in `Tests/Common.ps1`. Long term, I have opened #267 which poses the idea of switching over to mocking out `Invoke-WebRequest` for the majority of the tests, and instead focus on validating the data that it's sending matches the expected values per the API documentation, and having just a limited number of tests that do actual end-to-end testing. Fixes #264 --- Tests/Common.ps1 | 4 + Tests/GitHubAssignees.tests.ps1 | 41 ++++++++++ Tests/GitHubContents.tests.ps1 | 8 ++ Tests/GitHubIssues.tests.ps1 | 9 ++- Tests/GitHubLabels.tests.ps1 | 65 +++++++++++++++ Tests/GitHubProjects.tests.ps1 | 8 ++ Tests/GitHubRepositories.tests.ps1 | 109 +++++++++++++++++++++++++- Tests/GitHubRepositoryForks.tests.ps1 | 13 ++- 8 files changed, 251 insertions(+), 6 deletions(-) diff --git a/Tests/Common.ps1 b/Tests/Common.ps1 index 054eb7e8..41253602 100644 --- a/Tests/Common.ps1 +++ b/Tests/Common.ps1 @@ -100,6 +100,10 @@ function Initialize-CommonTestSetup Set-GitHubConfiguration -LogRequestBody # Make it easier to debug UT failures Set-GitHubConfiguration -MultiRequestProgressThreshold 0 # Status corrupts the raw CI logs for Linux and Mac, and makes runs take slightly longer. Set-GitHubConfiguration -DisableUpdateCheck # The update check is unnecessary during tests. + + # The number of seconds to sleep after performing some operations to ensure that successive + # API calls properly reflect previously updated state. + $script:defaultSleepSecondsForReliability = 3 } Initialize-CommonTestSetup diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index 64a694b5..0501f183 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -107,12 +107,22 @@ try Context 'Adding and removing an assignee via parameters' { $issue = $repo | New-GitHubIssue -Title "Test issue" + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have no assignees when created' { $issue.assignee.login | Should -BeNullOrEmpty $issue.assignees | Should -BeNullOrEmpty } $updatedIssue = Add-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Assignee $owner.login + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -144,12 +154,22 @@ try Context 'Adding an assignee with the repo on the pipeline' { $issue = $repo | New-GitHubIssue -Title "Test issue" + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have no assignees when created' { $issue.assignee.login | Should -BeNullOrEmpty $issue.assignees | Should -BeNullOrEmpty } $updatedIssue = $repo | Add-GitHubAssignee -Issue $issue.number -Assignee $owner.login + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -181,12 +201,22 @@ try Context 'Adding an assignee with the issue on the pipeline' { $issue = $repo | New-GitHubIssue -Title "Test issue" + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have no assignees when created' { $issue.assignee.login | Should -BeNullOrEmpty $issue.assignees | Should -BeNullOrEmpty } $updatedIssue = $issue | Add-GitHubAssignee -Assignee $owner.login + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -218,12 +248,22 @@ try Context 'Adding an assignee with the assignee user object on the pipeline' { $issue = $repo | New-GitHubIssue -Title "Test issue" + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have no assignees when created' { $issue.assignee.login | Should -BeNullOrEmpty $issue.assignees | Should -BeNullOrEmpty } $updatedIssue = $owner | Add-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -239,6 +279,7 @@ try } $updatedIssue = $owner | Remove-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Force + It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } diff --git a/Tests/GitHubContents.tests.ps1 b/Tests/GitHubContents.tests.ps1 index c1b9661e..a52ed473 100644 --- a/Tests/GitHubContents.tests.ps1 +++ b/Tests/GitHubContents.tests.ps1 @@ -37,6 +37,10 @@ try BeforeAll { # AutoInit will create a readme with the GUID of the repo name $repo = New-GitHubRepository -RepositoryName ($repoGuid) -AutoInit + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -260,6 +264,10 @@ try $repoName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repoName -AutoInit + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When setting new file content' { diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index ed5c4d88..1cff5d0c 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -161,7 +161,9 @@ try for ($i = 0; $i -lt 4; $i++) { $newIssues += New-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Title ([Guid]::NewGuid().Guid) - Start-Sleep -Seconds 1 # Needed to ensure that there is a unique creation timestamp between issues + + # Needed to ensure that there is a unique creation timestamp between issues + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } $newIssues[0] = Set-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed @@ -547,6 +549,11 @@ try } Lock-GitHubIssue -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $timeline = @(Get-GitHubIssueTimeline -OwnerName $script:OwnerName -RepositoryName $repo.name -Issue $issue.number) It 'Should have an event now' { $timeline.Count | Should -Be 1 diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index 5c3a1e30..8c635f0f 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -81,6 +81,10 @@ try $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + Initialize-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels } @@ -205,6 +209,10 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -319,6 +327,10 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -327,6 +339,11 @@ try Context 'Removing a label with parameters' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Force It 'Should be gone after being removed by parameter' { @@ -336,6 +353,11 @@ try Context 'Removing a label with the repo on the pipeline' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Remove-GitHubLabel -Label $label.name -Confirm:$false It 'Should be gone after being removed by parameter' { @@ -345,6 +367,11 @@ try Context 'Removing a label with the name on the pipeline' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $label.name | Remove-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Force It 'Should be gone after being removed by parameter' { @@ -354,6 +381,11 @@ try Context 'Removing a label with the label object on the pipeline' { $label = $repo | New-GitHubLabel -Label 'test' -Color 'CCCCCC' + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $label | Remove-GitHubLabel -Force It 'Should be gone after being removed by parameter' { @@ -366,6 +398,10 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -543,6 +579,10 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -617,6 +657,11 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Initialize-GitHubLabel -Label $defaultLabels } @@ -845,6 +890,11 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Initialize-GitHubLabel -Label $defaultLabels } @@ -911,6 +961,11 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Initialize-GitHubLabel -Label $defaultLabels } @@ -1078,6 +1133,11 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Initialize-GitHubLabel -Label $defaultLabels } @@ -1227,6 +1287,11 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repo | Initialize-GitHubLabel -Label $defaultLabels $milestone = $repo | New-GitHubMilestone -Title 'test milestone' diff --git a/Tests/GitHubProjects.tests.ps1 b/Tests/GitHubProjects.tests.ps1 index ccde85d6..3417c1d4 100644 --- a/Tests/GitHubProjects.tests.ps1 +++ b/Tests/GitHubProjects.tests.ps1 @@ -611,6 +611,10 @@ try $project = New-GitHubProject -OwnerName $script:ownerName -RepositoryName $repo.name -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc $null = Remove-GitHubProject -Project $project.id -Confirm:$false It 'Project should be removed' { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + {Get-GitHubProject -Project $project.id} | Should -Throw } } @@ -619,6 +623,10 @@ try $project = $repo | New-GitHubProject -ProjectName $defaultRepoProject -Description $defaultRepoProjectDesc $project | Remove-GitHubProject -Force It 'Project should be removed' { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + {$project | Get-GitHubProject} | Should -Throw } } diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 6fbcd27a..5ea84b12 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -125,6 +125,10 @@ try IsTemplate = $true } $repo = New-GitHubRepository @newGitHubRepositoryParms + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } It 'Should return an object of the correct type' { @@ -306,6 +310,10 @@ try } $templateRepo = New-GitHubRepository @newGitHubRepositoryParms + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When creating a public repository from a template' { @@ -321,7 +329,10 @@ try } $repo = New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms - Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } It 'Should have the expected type and addititional properties' { @@ -362,7 +373,10 @@ try } $repo = $templateRepo | New-GitHubRepositoryFromTemplate @newGitHubRepositoryFromTemplateParms - Start-Sleep -Seconds 1 # To work around a delay that GitHub may have with generating the repo + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } It 'Should have the expected type and addititional properties' { @@ -405,6 +419,10 @@ try BeforeAll { $publicRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Private + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When specify the visibility parameter' { @@ -485,7 +503,8 @@ try } It "Should return the correct membership order" { - for ($i = 1; $i -le $sortedRepos.count; $i++) { + for ($i = 1; $i -le $sortedRepos.count; $i++) + { $sortedRepos[$i].full_name | Should -Be $sortedRepoFullNames[$i] $sortedDescendingRepos[$i].full_name | Should -Be $sortedDescendingRepoFullNames[$i] } @@ -527,7 +546,8 @@ try } It 'Should return the correct properties' { - foreach ($repo in $repos) { + foreach ($repo in $repos) + { $repo.owner.login | Should -Be $ownerName } } @@ -536,6 +556,10 @@ try Context 'When getting a repository for a specified organization' { BeforeAll { $repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName ([Guid]::NewGuid().Guid) + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } It "Should have results for the organization" { @@ -553,6 +577,10 @@ try $repo1 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) $repo2 = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $repos = Get-GitHubRepository -GetAllPublicRepositories -Since $repo1.id } @@ -584,6 +612,10 @@ try } $repo = New-GitHubRepository @newGitHubRepositoryParms + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When specifiying the Uri parameter' { @@ -659,11 +691,21 @@ try It 'Should get no content using -Confirm:$false' { Remove-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Confirm:$false + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + { Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name } | Should -Throw } It 'Should get no content using -Force' { Remove-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Force + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + { Get-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name } | Should -Throw } } @@ -676,31 +718,55 @@ try $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $suffixToAddToRepo = "_renamed" $newRepoName = "$($repo.name)$suffixToAddToRepo" + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } It "Should have the expected new repository name - by URI" { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $renamedRepo = Rename-GitHubRepository -Uri ($repo.RepositoryUrl) -NewName $newRepoName -Force $renamedRepo.name | Should -Be $newRepoName } It "Should have the expected new repository name - by Elements" { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $renamedRepo = Rename-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -NewName $newRepoName -Confirm:$false $renamedRepo.name | Should -Be $newRepoName } It "Should work via the pipeline" { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $renamedRepo = $repo | Rename-GitHubRepository -NewName $newRepoName -Confirm:$false $renamedRepo.name | Should -Be $newRepoName $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' } It "Should be possible to rename with Set-GitHubRepository too" { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $renamedRepo = $repo | Set-GitHubRepository -NewName $newRepoName -Confirm:$false $renamedRepo.name | Should -Be $newRepoName $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' } AfterEach -Scriptblock { + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + Remove-GitHubRepository -Uri "$($repo.svn_url)$suffixToAddToRepo" -Confirm:$false } } @@ -712,6 +778,10 @@ try BeforeAll -ScriptBlock { $repoName = ([Guid]::NewGuid().Guid) $repo = New-GitHubRepository -RepositoryName $repoName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context -Name 'When updating a repository with all possible settings' { @@ -731,6 +801,7 @@ try DeleteBranchOnMerge = $true IsTemplate = $true } + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } @@ -763,6 +834,7 @@ try DisallowMergeCommit = $false DisallowRebaseMerge = $true } + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } @@ -785,6 +857,7 @@ try RepositoryName = $repoName Archived = $true } + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } @@ -811,11 +884,16 @@ try $repoName = ([Guid]::NewGuid().Guid) $repo = New-GitHubRepository -RepositoryName $repoName -Private + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $updateGithubRepositoryParms = @{ OwnerName = $repo.owner.login RepositoryName = $repoName Private = $false } + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } @@ -865,6 +943,11 @@ try It 'Should be removable by the pipeline' { ($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + { $repo | Get-GitHubRepository } | Should -Throw } } @@ -900,6 +983,11 @@ try It 'Should be removable by the pipeline' { ($repo | Remove-GitHubRepository -Confirm:$false) | Should -BeNullOrEmpty + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + { $repo | Get-GitHubRepository } | Should -Throw } } @@ -970,6 +1058,11 @@ try Describe 'GitHubRepositories\Set-GitHubRepositoryTopic' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability + $topic = Set-GitHubRepositoryTopic -OwnerName $repo.owner.login -RepositoryName $repo.name -Name $defaultRepoTopic } @@ -1249,6 +1342,10 @@ try Describe 'GitHubRepositories\Enable-GitHubRepositoryVulnerabilityAlert' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When Enabling GitHub Repository Vulnerability Alerts' { @@ -1284,6 +1381,10 @@ try Describe 'GitHubRepositories\Enable-GitHubRepositorySecurityFix' { BeforeAll { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } Context 'When Enabling GitHub Repository Security Fixes' { diff --git a/Tests/GitHubRepositoryForks.tests.ps1 b/Tests/GitHubRepositoryForks.tests.ps1 index 7ea08eb1..b4cd6f46 100644 --- a/Tests/GitHubRepositoryForks.tests.ps1 +++ b/Tests/GitHubRepositoryForks.tests.ps1 @@ -29,6 +29,10 @@ try Context 'When a new fork is created' { BeforeAll { $repo = New-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -54,6 +58,10 @@ try BeforeAll { $upstream = Get-GitHubRepository -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName $repo = $upstream | New-GitHubRepositoryFork + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { @@ -80,10 +88,13 @@ try Context 'When a new fork is created' { BeforeAll { $repo = New-GitHubRepositoryFork -OwnerName $script:upstreamOwnerName -RepositoryName $script:upstreamRepositoryName -OrganizationName $script:organizationName + + # The CI build has been unreliable with this test. + # Adding a short sleep to ensure successive queries reflect updated state. + Start-Sleep -Seconds $script:defaultSleepSecondsForReliability } AfterAll { - Start-Sleep -Seconds 3 # Trying to avoid an issue with deleting the repo if it's still being created by GitHub $repo | Remove-GitHubRepository -Force }