Configure Systemd Socket Activation

as new way for Poseidon to accept connections. This should reduce our issues caused by deployments.
This commit is contained in:
Maximilian Paß
2023-12-02 16:56:43 +01:00
parent eaa022282c
commit eaddc65989
11 changed files with 128 additions and 58 deletions

View File

@@ -1,7 +1,6 @@
package recovery
import (
"context"
"encoding/json"
"flag"
nomadApi "github.com/hashicorp/nomad/api"
@@ -29,7 +28,6 @@ import (
var (
log = logging.GetLogger("e2e-recovery")
testDockerImage = flag.String("dockerImage", "", "Docker image to use in E2E tests")
poseidonBinary = flag.String("poseidonPath", "", "The path to the Poseidon binary")
nomadClient *nomadApi.Client
nomadNamespace string
)
@@ -42,8 +40,7 @@ const (
type E2ERecoveryTestSuite struct {
suite.Suite
runnerID string
poseidonCancel context.CancelFunc
runnerID string
}
// Overwrite TestMain for custom setup.
@@ -51,10 +48,6 @@ func TestMain(m *testing.M) {
if err := config.InitConfig(); err != nil {
log.WithError(err).Fatal("Could not initialize configuration")
}
if *poseidonBinary == "" {
log.Fatal("You must specify the -path to the Poseidon binary!")
}
if *testDockerImage == "" {
log.Fatal("You must specify the -dockerImage flag!")
}
@@ -77,20 +70,12 @@ func TestMain(m *testing.M) {
func TestE2ERecoveryTests(t *testing.T) {
testSuite := new(E2ERecoveryTestSuite)
ctx, cancelPoseidon := context.WithCancel(context.Background())
testSuite.poseidonCancel = cancelPoseidon
startPoseidon(ctx, cancelPoseidon)
waitForPoseidon()
e2e.CreateDefaultEnvironment(PrewarmingPoolSize, *testDockerImage)
e2e.WaitForDefaultEnvironment()
suite.Run(t, testSuite)
TearDown()
testSuite.poseidonCancel()
<-time.After(tests.ShortTimeout)
}
func (s *E2ERecoveryTestSuite) TestInactivityTimer_Valid() {
@@ -99,6 +84,7 @@ func (s *E2ERecoveryTestSuite) TestInactivityTimer_Valid() {
}
func (s *E2ERecoveryTestSuite) TestInactivityTimer_Expired() {
waitForPoseidon() // The timeout begins only when the runner is recovered.
<-time.After(InactivityTimeout * time.Second)
_, err := e2e.ProvideWebSocketURL(s.runnerID, &dto.ExecutionRequest{Command: "true"})
s.Error(err)

View File

@@ -1,15 +1,13 @@
package recovery
import (
"context"
"github.com/openHPI/poseidon/internal/api"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/openHPI/poseidon/tests"
"github.com/openHPI/poseidon/tests/e2e"
"github.com/openHPI/poseidon/tests/helpers"
"github.com/shirou/gopsutil/v3/process"
"net/http"
"os"
"os/exec"
"time"
)
@@ -27,12 +25,8 @@ func (s *E2ERecoveryTestSuite) SetupTest() {
}
<-time.After(tests.ShortTimeout)
s.poseidonCancel()
killPoseidon()
<-time.After(tests.ShortTimeout)
ctx, cancelPoseidon := context.WithCancel(context.Background())
s.poseidonCancel = cancelPoseidon
startPoseidon(ctx, cancelPoseidon)
waitForPoseidon()
}
func TearDown() {
@@ -43,16 +37,6 @@ func TearDown() {
}
}
func startPoseidon(ctx context.Context, cancelPoseidon context.CancelFunc) {
poseidon := exec.CommandContext(ctx, *poseidonBinary) //nolint:gosec // We accept that another binary can be executed.
poseidon.Stdout = os.Stdout
poseidon.Stderr = os.Stderr
if err := poseidon.Start(); err != nil {
cancelPoseidon()
log.WithError(err).Fatal("Failed to start Poseidon")
}
}
func waitForPoseidon() {
done := false
for !done {
@@ -61,3 +45,24 @@ func waitForPoseidon() {
done = err == nil && resp.StatusCode == http.StatusNoContent
}
}
func killPoseidon() {
processes, err := process.Processes()
if err != nil {
log.WithError(err).Error("Error listing processes")
}
for _, p := range processes {
n, err := p.Name()
if err != nil {
continue
}
if n == "poseidon" {
err = p.Kill()
if err != nil {
log.WithError(err).Error("Error killing Poseidon")
} else {
log.Info("Killed Poseidon")
}
}
}
}