[MM-65837], [MM-65824] - Update Dependencies (#33972) (#34052)

* Update github.com/mholt/archives

* Update github.com/spf13/viper

* make batch migration worker tests less flaky

---------

Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>
Этот коммит содержится в:
Jesse Hallam
2025-10-03 11:12:25 -03:00
коммит произвёл GitHub
родитель 891a006890
Коммит 9dd2c6f54f
5 изменённых файлов: 127 добавлений и 110 удалений

Просмотреть файл

@@ -27,6 +27,7 @@ import (
"github.com/mattermost/mattermost/server/public/plugin/plugintest"
"github.com/mattermost/mattermost/server/public/plugin/utils"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
)
@@ -1262,7 +1263,6 @@ func TestHookReactionHasBeenAdded(t *testing.T) {
defer th.TearDown()
var mockAPI plugintest.API
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
mockAPI.On("LogDebug", "smile").Return(nil)
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
@@ -1298,6 +1298,10 @@ func TestHookReactionHasBeenAdded(t *testing.T) {
}
_, err := th.App.SaveReactionForPost(th.Context, reaction)
require.Nil(t, err)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
mockAPI.AssertExpectations(&testutils.CollectTWithLogf{CollectT: c})
}, 5*time.Second, 100*time.Millisecond)
}
func TestHookReactionHasBeenRemoved(t *testing.T) {
@@ -1306,7 +1310,6 @@ func TestHookReactionHasBeenRemoved(t *testing.T) {
defer th.TearDown()
var mockAPI plugintest.API
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
mockAPI.On("LogDebug", "star").Return(nil)
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
@@ -1345,9 +1348,9 @@ func TestHookReactionHasBeenRemoved(t *testing.T) {
require.Nil(t, err)
require.Eventually(t, func() bool {
return mockAPI.AssertCalled(t, "LogDebug", "star")
}, 2*time.Second, 100*time.Millisecond)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
mockAPI.AssertExpectations(&testutils.CollectTWithLogf{CollectT: c})
}, 5*time.Second, 100*time.Millisecond)
}
func TestHookRunDataRetention(t *testing.T) {
@@ -1761,15 +1764,15 @@ func TestHookPreferencesHaveChanged(t *testing.T) {
mockAPI.On("LogDebug", "category=test_category name=test_name_1 value=test_value_1")
mockAPI.On("LogDebug", "category=test_category name=test_name_2 value=test_value_2")
defer mockAPI.AssertExpectations(t)
// Run test
err := th.App.UpdatePreferences(th.Context, th.BasicUser.Id, preferences)
require.Nil(t, err)
// Hooks are run in a goroutine, so wait for those to complete
time.Sleep(2 * time.Second)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
mockAPI.AssertExpectations(&testutils.CollectTWithLogf{CollectT: c})
}, 5*time.Second, 100*time.Millisecond)
})
t.Run("should be called when preferences are changed by plugin code", func(t *testing.T) {
@@ -1919,11 +1922,12 @@ func TestChannelHasBeenCreated(t *testing.T) {
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
require.Nil(t, appErr)
assert.True(t, len(posts.Order) > 0)
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
if assert.NotEmpty(t, posts.Order) {
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
}
}, 5*time.Second, 100*time.Millisecond)
})
@@ -1946,10 +1950,11 @@ func TestChannelHasBeenCreated(t *testing.T) {
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
require.Nil(t, appErr)
assert.True(t, len(posts.Order) > 0)
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
if assert.NotEmpty(t, posts.Order) {
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
}
}, 5*time.Second, 100*time.Millisecond)
})
@@ -1973,10 +1978,11 @@ func TestChannelHasBeenCreated(t *testing.T) {
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
require.Nil(t, appErr)
assert.True(t, len(posts.Order) > 0)
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
if assert.NotEmpty(t, posts.Order) {
post := posts.Posts[posts.Order[0]]
assert.Equal(t, channel.Id, post.ChannelId)
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
}
}, 5*time.Second, 100*time.Millisecond)
})
}

Просмотреть файл

@@ -75,11 +75,14 @@ func TestBatchMigrationWorker(t *testing.T) {
waitDone(t, stopped, "worker did not stop")
}
assertJobReset := func(t *testing.T, th *TestHelper, job *model.Job) {
actualJob, appErr := th.Server.Jobs.GetJob(th.Context, job.Id)
require.Nil(t, appErr)
assert.Empty(t, actualJob.Progress)
assert.Empty(t, actualJob.Data)
assertJobResetEventually := func(t *testing.T, th *TestHelper, job *model.Job) {
t.Helper()
assert.EventuallyWithT(t, func(t *assert.CollectT) {
actualJob, appErr := th.Server.Jobs.GetJob(th.Context, job.Id)
require.Nil(t, appErr)
assert.Empty(t, actualJob.Progress, "expected no job progress")
assert.Empty(t, actualJob.Data, "expected no job data")
}, 5*time.Second, 250*time.Millisecond, "job never reset")
}
getBatchNumberFromData := func(t *testing.T, data model.StringMap) int {
@@ -142,14 +145,11 @@ func TestBatchMigrationWorker(t *testing.T) {
return nil, false, nil
})
// Give the worker time to start running
time.Sleep(500 * time.Millisecond)
// Queue the work to be done
worker.JobChannel() <- *job
th.WaitForJobStatus(t, job, model.JobStatusPending)
assertJobReset(t, th, job)
assertJobResetEventually(t, th, job)
stopWorker(t, worker)
})
@@ -171,14 +171,11 @@ func TestBatchMigrationWorker(t *testing.T) {
return getDataFromBatchNumber(batchNumber), false, nil
})
// Give the worker time to start running
time.Sleep(500 * time.Millisecond)
// Queue the work to be done
worker.JobChannel() <- *job
th.WaitForJobStatus(t, job, model.JobStatusPending)
assertJobReset(t, th, job)
assertJobResetEventually(t, th, job)
stopWorker(t, worker)
})

Просмотреть файл

@@ -15,10 +15,23 @@ import (
"time"
"github.com/mattermost/mattermost/server/v8/channels/utils"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
)
// CollectTWithLogf adds Logf to assert.CollectT to make this pattern possible:
//
// assert.EventuallyWithT(t, func(c *assert.CollectT) {
// mockAPI.AssertExpectations(&testutils.CollectTWithLogf{CollectT: c})
// }, 5*time.Second, 100*time.Millisecond)
type CollectTWithLogf struct {
*assert.CollectT
}
func (*CollectTWithLogf) Logf(string, ...any) {
}
func ReadTestFile(name string) ([]byte, error) {
path, _ := fileutils.FindDir("tests")
file, err := os.Open(filepath.Join(path, name))