forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag to allow setting a shutdown wait period
Fixes open-policy-agent#2764 Signed-off-by: Björn Carlsson <bjorn.carlsson@bisnode.com>
- Loading branch information
Björn Carlsson
committed
Oct 28, 2020
1 parent
d8947db
commit 012fbfd
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020 The OPA Authors. All rights reserved. | ||
// Use of this source code is governed by an Apache2 | ||
// license that can be found in the LICENSE file. | ||
package shutdown | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/open-policy-agent/opa/test/e2e" | ||
) | ||
|
||
var testRuntime *e2e.TestRuntime | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
testServerParams := e2e.NewAPIServerTestParams() | ||
|
||
testServerParams.GracefulShutdownPeriod = 1 | ||
testServerParams.ShutdownWaitPeriod = 2 | ||
|
||
var err error | ||
testRuntime, err = e2e.NewTestRuntime(testServerParams) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(testRuntime.RunTests(m)) | ||
} | ||
|
||
func TestShutdownWaitPeriod(t *testing.T) { | ||
proc, err := os.FindProcess(os.Getpid()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = proc.Signal(os.Interrupt) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
time.Sleep(1500 * time.Millisecond) | ||
|
||
// Ensure that OPA i still running | ||
err = testRuntime.HealthCheck(testRuntime.URL()) | ||
if err != nil { | ||
t.Fatalf("Expected health endpoint to be up but got:\n\n%v", err) | ||
} | ||
} |