Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

84 lines
1.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package cluster
import (
"fmt"
"runtime"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/hanzoteam/server/server/public/model"
)
func TestMemFootprint(t *testing.T) {
var memConsumed = func() uint64 {
runtime.GC()
var s runtime.MemStats
runtime.ReadMemStats(&s)
return s.Sys
}
t.Run("average k per jobOnce", func(t *testing.T) {
t.SkipNow()
makeKey := model.NewId
numJobs := 100000
jobs := make(map[string]*int32, numJobs)
for range numJobs {
jobs[makeKey()] = new(int32)
}
callback := func(key string, _ any) {
count, ok := jobs[key]
if ok {
atomic.AddInt32(count, 1)
}
}
mockPluginAPI := newMockPluginAPI(t)
s := GetJobOnceScheduler(mockPluginAPI)
err := s.SetCallback(callback)
require.NoError(t, err)
err = s.Start()
require.NoError(t, err)
getVal := func(key string) []byte {
data, _ := s.pluginAPI.KVGet(key)
return data
}
before := memConsumed()
for k := range jobs {
assert.Empty(t, getVal(oncePrefix+k))
_, err = s.ScheduleOnce(k, time.Now().Add(5*time.Minute), nil)
require.NoError(t, err)
assert.NotEmpty(t, getVal(oncePrefix+k))
}
time.Sleep(10 * time.Second)
// Everything scheduled now:
s.activeJobs.mu.RLock()
assert.Equal(t, numJobs, len(s.activeJobs.jobs))
s.activeJobs.mu.RUnlock()
list, err := s.ListScheduledJobs()
require.NoError(t, err)
assert.Equal(t, numJobs, len(list))
after := memConsumed()
fmt.Printf("\nthe %d jobs, scheduler, and goroutines require: %.2fmB memory, or %.3fkB each job\n",
numJobs,
float64(after-before)/(1024*1024),
(float64(after-before)/float64(numJobs))/1024)
})
}