-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package alloc_logs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/e2e/e2eutil" | ||
"github.com/hashicorp/nomad/helper/uuid" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
func TestAllocLogs(t *testing.T) { | ||
|
||
// Wait until we have a usable cluster before running the tests. | ||
nomadClient := e2eutil.NomadClient(t) | ||
e2eutil.WaitForLeader(t, nomadClient) | ||
e2eutil.WaitForNodesReady(t, nomadClient, 1) | ||
|
||
// Run our test cases. | ||
t.Run("TestAllocLogs_MixedFollow", testMixedFollow) | ||
} | ||
|
||
func testMixedFollow(t *testing.T) { | ||
|
||
nomadClient := e2eutil.NomadClient(t) | ||
|
||
// Generate our job ID which will be used for the entire test. | ||
jobID := "alloc-logs-mixed-follow-" + uuid.Short() | ||
jobIDs := []string{jobID} | ||
|
||
// Ensure jobs are cleaned. | ||
t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs)) | ||
|
||
allocStubs := e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "./input/mixed-output.nomad", jobID, "") | ||
must.Len(t, 1, allocStubs) | ||
|
||
// Run the alloc logs command which we expect to capture both stdout and | ||
// stderr logs. The command will reach its timeout and therefore return an | ||
// error. We want to ignore this, as it's expected. Any other error is | ||
// terminal. | ||
out, err := e2eutil.Command("nomad", "alloc", "logs", "-f", allocStubs[0].ID) | ||
if err != nil { | ||
must.ErrorContains(t, err, "failed: signal: killed") | ||
} | ||
must.StrContains(t, out, "stdout\nstderr\nstdout\nstderr\nstdout\nstderr") | ||
} |
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,6 @@ | ||
// Package alloc_logs provides end-to-end tests for Nomads allocation logging | ||
// functionality. | ||
// | ||
// In order to run this test suite only, from the e2e directory you can trigger | ||
// go test -v -run '^TestAllocLogs' ./alloc_logs | ||
package alloc_logs |
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,35 @@ | ||
job "alloc-logs" { | ||
datacenters = ["dc1"] | ||
type = "service" | ||
|
||
#constraint { | ||
# attribute = "${attr.kernel.name}" | ||
# value = "linux" | ||
#} | ||
|
||
group "alloc-logs" { | ||
|
||
task "test" { | ||
driver = "raw_exec" | ||
|
||
template { | ||
data = <<EOH | ||
while true | ||
do | ||
echo stdout >&1 | ||
sleep 1 | ||
echo stderr >&2 | ||
sleep 1 | ||
done | ||
EOH | ||
|
||
destination = "local/echo.sh" | ||
} | ||
|
||
config { | ||
command = "bash" | ||
args = ["local/echo.sh"] | ||
} | ||
} | ||
} | ||
} |