Skip to content

Commit

Permalink
Merge pull request #1919 from fenxiong/fix-oom
Browse files Browse the repository at this point in the history
Fix Windows Functional Tests
  • Loading branch information
fenxiong authored Mar 4, 2019
2 parents e7af32a + ab84b38 commit 92dd8b4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
5 changes: 3 additions & 2 deletions agent/engine/ordering_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ func TestDependencyHealthCheck(t *testing.T) {
dependency := createTestContainerWithImageAndName(baseImageForOS, "dependency")

parent.EntryPoint = &entryPointForOS
parent.Command = []string{"sleep 5 && exit 1"}
parent.Command = []string{"exit 0"}
parent.DependsOn = []apicontainer.DependsOn{
{
ContainerName: "dependency",
Condition: "HEALTHY",
},
}
parent.Essential = true

dependency.EntryPoint = &entryPointForOS
dependency.Command = []string{"sleep 60 && exit 0"}
dependency.Command = []string{"sleep 90"}
dependency.HealthCheckType = apicontainer.DockerHealthCheckType
dependency.DockerConfig.Config = aws.String(alwaysHealthyHealthCheckConfig)

Expand Down
2 changes: 0 additions & 2 deletions agent/functional_tests/tests/functionaltests_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ func TestOOMContainer(t *testing.T) {

testTask, err := agent.StartTask(t, "oom-windows")
require.NoError(t, err, "Expected to start invalid-image task")
err = testTask.WaitRunning(waitTaskStateChangeDuration)
assert.NoError(t, err, "Expect task to be running")
err = testTask.WaitStopped(waitTaskStateChangeDuration)
assert.NoError(t, err, "Expect task to be stopped")
assert.NotEqual(t, 0, testTask.Containers[0].ExitCode, "container should fail with memory error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
$oldPref = $ErrorActionPreference
$ErrorActionPreference = 'Stop'

Invoke-Expression ${PSScriptRoot}\..\windows-deploy\hostsetup.ps1

# Create amazon/amazon-ecs-v3-task-endpoint-validator-windows for tests
Invoke-Expression "go build -o ${PSScriptRoot}\v3-task-endpoint-validator-windows.exe ${PSScriptRoot}\v3-task-endpoint-validator-windows.go"
Invoke-Expression "docker build -t amazon/amazon-ecs-v3-task-endpoint-validator-windows --file ${PSScriptRoot}\v3-task-endpoint-validator-windows.dockerfile ${PSScriptRoot}"
Expand Down
33 changes: 32 additions & 1 deletion misc/windows-deploy/hostsetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,39 @@ $dockerSubnet = (docker network inspect nat | ConvertFrom-Json).IPAM.Config.Subn
$ip = (Get-NetRoute -InterfaceIndex $ifIndex -DestinationPrefix $dockerSubnet)
if(!($ip)) {

$IPAddrParams = @{
InterfaceIndex = $ifIndex;
IPAddress = $credentialAddress;
PrefixLength = 32;
}

# This command tells the APIPA interface that this IP exists.
New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $credentialAddress -PrefixLength 32
New-NetIPAddress @IPAddrParams

[int]$delay = 1
[int]$maxTries = 10
[bool]$available = $false
while (-not $available -and $maxTries -ge 0) {
try {
$IPAddr = Get-NetIPAddress @IPAddrParams -ErrorAction:Ignore
if ($IPAddr) {
if ($($IPAddr.AddressState) -eq "Preferred") {
$available = $true
break;
} else {
Start-Sleep -Seconds $delay
$maxTries--
}
}
} catch {
# Prevent race condition where the adapter has multiple addresses before our new ip is assigned
# Note: Allowing this race condition can cause the netsh interface portproxy setup to result
# in the network adapter in an unrecoverable bad state where the proxy is unable to
# listen on port 80 because the port is in use by a non-functional proxy rule.
Start-Sleep -Seconds $delay
$maxTries--
}
}

# Enable the default docker IP range to be routable by the APIPA interface.
New-NetRoute -DestinationPrefix $dockerSubnet -ifIndex $ifindex
Expand Down

0 comments on commit 92dd8b4

Please sign in to comment.