Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/code.cloudfoundry.org/inigo/cell/assets/fake_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os/exec"
"path/filepath"
"runtime"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -26,6 +27,10 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {

AfterEach(func() {
gexec.CleanupBuildArtifacts()
// On Windows, add a small delay to ensure ports are released
if runtime.GOOS == "windows" {
time.Sleep(500 * time.Millisecond)
}
})

DescribeTable("fake app should exit with correct exit codes",
Expand Down Expand Up @@ -62,7 +67,7 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {
actualExitCode := session.ExitCode()
if exitCode == 134 {
// SIGABRT simulation via panic results in exit code 2 cross-platform
Expect(actualExitCode).To(Equal(2),
Expect(actualExitCode).To(Equal(2),
fmt.Sprintf("Expected panic exit code 2 for SIGABRT simulation, got %d", actualExitCode))
} else {
Expect(actualExitCode).To(Equal(exitCode))
Expand All @@ -80,6 +85,17 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for server to start
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand Down Expand Up @@ -109,6 +125,17 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for server to start
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand Down Expand Up @@ -138,6 +165,17 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for app to start listening
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand All @@ -152,8 +190,14 @@ var _ = Describe("Fake App Exit Behavior", Serial, func() {
// Send SIGTERM to simulate natural shutdown
session.Terminate()

// Should exit with code 42
Eventually(session, 10*time.Second).Should(gexec.Exit(143))
// Cross-platform exit code handling
if runtime.GOOS == "windows" {
// Windows doesn't have SIGTERM, process exits naturally
Eventually(session, 10*time.Second).Should(gexec.Exit(42))
} else {
// Unix systems: SIGTERM results in exit code 143 (128 + 15)
Eventually(session, 10*time.Second).Should(gexec.Exit(143))
}
})
})
})
61 changes: 58 additions & 3 deletions src/code.cloudfoundry.org/inigo/cell/assets/fake_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os/exec"
"path/filepath"
"runtime"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -26,6 +27,10 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {

AfterEach(func() {
gexec.CleanupBuildArtifacts()
// On Windows, add a small delay to ensure ports are released
if runtime.GOOS == "windows" {
time.Sleep(500 * time.Millisecond)
}
})

// Helper function for normal exit codes
Expand All @@ -35,6 +40,17 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for proxy to start listening on port 61001
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand Down Expand Up @@ -63,6 +79,17 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for proxy to start listening on port 61001
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand All @@ -85,7 +112,7 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {

// Verify SIGABRT simulation exit code (panic results in exit code 2)
actualExitCode := session.ExitCode()
Expect(actualExitCode).To(Equal(2),
Expect(actualExitCode).To(Equal(2),
fmt.Sprintf("Expected panic exit code 2 for SIGABRT simulation, got %d", actualExitCode))
}

Expand All @@ -109,6 +136,17 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for proxy to start
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand Down Expand Up @@ -154,6 +192,17 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

// Ensure cleanup on test completion
defer func() {
if session.ExitCode() == -1 { // Process still running
session.Kill()
}
// On Windows, add extra cleanup time
if runtime.GOOS == "windows" {
time.Sleep(100 * time.Millisecond)
}
}()

// Wait for proxy to start listening
Eventually(func() error {
client := &http.Client{Timeout: 1 * time.Second}
Expand All @@ -168,7 +217,13 @@ var _ = Describe("Fake Proxy Exit Behavior", Serial, func() {
// Send SIGTERM to simulate natural shutdown
session.Terminate()

// Should exit with code 42
Eventually(session, 10*time.Second).Should(gexec.Exit(143))
// Cross-platform exit code handling
if runtime.GOOS == "windows" {
// Windows doesn't have SIGTERM, process exits naturally
Eventually(session, 10*time.Second).Should(gexec.Exit(42))
} else {
// Unix systems: SIGTERM results in exit code 143 (128 + 15)
Eventually(session, 10*time.Second).Should(gexec.Exit(143))
}
})
})
Loading