[MM-63561] - Job server: Fix read after write (#32527)

* fix read after write

* clean up tests
This commit is contained in:
Christopher Poile
2025-11-11 13:21:03 -05:00
committed by GitHub
parent be97680dcb
commit ef6241f9b1
2 changed files with 2 additions and 20 deletions
+1 -6
View File
@@ -253,12 +253,7 @@ func (srv *JobServer) RequestCancellation(rctx request.CTX, jobId string) *model
}
if newJob != nil {
if srv.metrics != nil {
job, err := srv.GetJob(rctx, jobId)
if err != nil {
return model.NewAppError("RequestCancellation", "app.job.update.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
srv.metrics.DecrementJobActive(job.Type)
srv.metrics.DecrementJobActive(newJob.Type)
}
return nil
+1 -14
View File
@@ -10,13 +10,11 @@ import (
"os"
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
@@ -641,17 +639,9 @@ func TestRequestCancellation(t *testing.T) {
t.Run("cancelled, job not found", func(t *testing.T) {
jobServer, mockStore, _ := makeJobServer(t)
job := &model.Job{
Id: "job_id",
Type: "job_type",
}
mockStore.JobStore.
On("UpdateStatusOptimistically", "job_id", model.JobStatusPending, model.JobStatusCanceled).
Return(job, nil)
mockStore.JobStore.
On("Get", mock.AnythingOfType("*request.Context"), "job_id").
Return(nil, &store.ErrNotFound{})
Return(nil, errors.New("failed to update Job with id=job_id"))
err := jobServer.RequestCancellation(ctx, "job_id")
expectErrorId(t, "app.job.update.app_error", err)
@@ -668,9 +658,6 @@ func TestRequestCancellation(t *testing.T) {
mockStore.JobStore.
On("UpdateStatusOptimistically", "job_id", model.JobStatusPending, model.JobStatusCanceled).
Return(job, nil)
mockStore.JobStore.
On("Get", mock.AnythingOfType("*request.Context"), "job_id").
Return(job, nil)
mockMetrics.On("DecrementJobActive", "job_type")
err := jobServer.RequestCancellation(ctx, "job_id")