-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent double job status update (#9768)
* Prevent Job Statuses from being calculated twice #8435 introduced atomic eval insertion iwth job (de-)registration. This change removes a now obsolete guard which checked if the index was equal to the job.CreateIndex, which would empty the status. Now that the job regisration eval insetion is atomic with the registration this check is no longer necessary to set the job statuses correctly. * test to ensure only single job event for job register * periodic e2e * separate job update summary step * fix updatejobstability to use copy instead of modified reference of job * update envoygatewaybindaddresses copy to prevent job diff on null vs empty * set ConsulGatewayBindAddress to empty map instead of nil fix nil assertions for empty map rm unnecessary guard
- Loading branch information
1 parent
b6aa995
commit f7045c0
Showing
13 changed files
with
293 additions
and
85 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
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,28 @@ | ||
job "periodic" { | ||
datacenters = ["dc1"] | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
|
||
periodic { | ||
cron = "* * * * *" | ||
prohibit_overlap = true | ||
} | ||
|
||
group "group" { | ||
task "task" { | ||
driver = "docker" | ||
|
||
config { | ||
image = "busybox:1" | ||
command = "/bin/sh" | ||
args = ["-c", "sleep 5"] | ||
} | ||
} | ||
} | ||
} | ||
|
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,82 @@ | ||
package periodic | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/nomad/e2e/e2eutil" | ||
"github.com/hashicorp/nomad/e2e/framework" | ||
"github.com/hashicorp/nomad/helper/uuid" | ||
"github.com/hashicorp/nomad/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type PeriodicTest struct { | ||
framework.TC | ||
jobIDs []string | ||
} | ||
|
||
func init() { | ||
framework.AddSuites(&framework.TestSuite{ | ||
Component: "Periodic", | ||
CanRunLocal: true, | ||
Cases: []framework.TestCase{ | ||
new(PeriodicTest), | ||
}, | ||
}) | ||
} | ||
|
||
func (tc *PeriodicTest) BeforeAll(f *framework.F) { | ||
e2eutil.WaitForLeader(f.T(), tc.Nomad()) | ||
} | ||
|
||
func (tc *PeriodicTest) AfterEach(f *framework.F) { | ||
nomadClient := tc.Nomad() | ||
j := nomadClient.Jobs() | ||
|
||
for _, id := range tc.jobIDs { | ||
j.Deregister(id, true, nil) | ||
} | ||
_, err := e2eutil.Command("nomad", "system", "gc") | ||
f.NoError(err) | ||
} | ||
|
||
func (tc *PeriodicTest) TestPeriodicDispatch_Basic(f *framework.F) { | ||
t := f.T() | ||
|
||
uuid := uuid.Generate() | ||
jobID := fmt.Sprintf("periodicjob-%s", uuid[0:8]) | ||
tc.jobIDs = append(tc.jobIDs, jobID) | ||
|
||
// register job | ||
e2eutil.Register(jobID, "periodic/input/simple.nomad") | ||
|
||
// force dispatch | ||
require.NoError(t, e2eutil.PeriodicForce(jobID)) | ||
|
||
// Get the child job ID | ||
childID, err := e2eutil.JobInspectTemplate(jobID, `{{with index . 1}}{{printf "%s" .ID}}{{end}}`) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, childID) | ||
|
||
testutil.WaitForResult(func() (bool, error) { | ||
status, err := e2eutil.JobInspectTemplate(jobID, `{{with index . 1}}{{printf "%s" .Status}}{{end}}`) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, status) | ||
if status == "dead" { | ||
return true, nil | ||
} | ||
return false, fmt.Errorf("expected periodic job to be dead, got %s", status) | ||
}, func(err error) { | ||
require.NoError(t, err) | ||
}) | ||
|
||
// Assert there are no pending children | ||
pending, err := e2eutil.JobInspectTemplate(jobID, `{{with index . 0}}{{printf "%d" .JobSummary.Children.Pending}}{{end}}`) | ||
require.NoError(t, err) | ||
require.Equal(t, "0", pending) | ||
|
||
// Assert there are no pending children | ||
dead, err := e2eutil.JobInspectTemplate(jobID, `{{with index . 0}}{{printf "%d" .JobSummary.Children.Dead}}{{end}}`) | ||
require.NoError(t, err) | ||
require.Equal(t, "1", dead) | ||
} |
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
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
Oops, something went wrong.