diff --git a/src/code.cloudfoundry.org/inigo/cell/assets/fake_app_test.go b/src/code.cloudfoundry.org/inigo/cell/assets/fake_app_test.go index b3a9c7873..d05c8c43e 100644 --- a/src/code.cloudfoundry.org/inigo/cell/assets/fake_app_test.go +++ b/src/code.cloudfoundry.org/inigo/cell/assets/fake_app_test.go @@ -5,6 +5,7 @@ import ( "net/http" "os/exec" "path/filepath" + "runtime" "time" . "github.com/onsi/ginkgo/v2" @@ -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", @@ -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)) @@ -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} @@ -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} @@ -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} @@ -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)) + } }) }) }) diff --git a/src/code.cloudfoundry.org/inigo/cell/assets/fake_proxy_test.go b/src/code.cloudfoundry.org/inigo/cell/assets/fake_proxy_test.go index 4d3446f12..d7e88931d 100644 --- a/src/code.cloudfoundry.org/inigo/cell/assets/fake_proxy_test.go +++ b/src/code.cloudfoundry.org/inigo/cell/assets/fake_proxy_test.go @@ -5,6 +5,7 @@ import ( "net/http" "os/exec" "path/filepath" + "runtime" "time" . "github.com/onsi/ginkgo/v2" @@ -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 @@ -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} @@ -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} @@ -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)) } @@ -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} @@ -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} @@ -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)) + } }) })