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

116 lines
2.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package sqlstore
import (
"sync"
"testing"
"golang.org/x/sync/errgroup"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/shared/mlog"
"github.com/hanzoteam/server/server/v8/channels/store/storetest"
)
// TestPool is used to facilitate the efficient (and safe) use of test stores in parallel tests (e.g. in api4, app, sqlstore).
type TestPool struct {
entries map[string]*TestPoolEntry
mut sync.Mutex
logger mlog.LoggerIFace
}
type TestPoolEntry struct {
Store *SqlStore
Settings *model.SqlSettings
}
func NewTestPool(logger mlog.LoggerIFace, driverName string, poolSize int) (*TestPool, error) {
logger.Info("Creating test store pool", mlog.Int("poolSize", poolSize))
entries := make(map[string]*TestPoolEntry, poolSize)
var mut sync.Mutex
var eg errgroup.Group
for range poolSize {
eg.Go(func() error {
settings := storetest.MakeSqlSettings(driverName)
sqlStore, err := New(*settings, logger, nil, WithFeatureFlags(func() *model.FeatureFlags {
return &model.FeatureFlags{CJKSearch: true}
}), DisableMorphLogging())
if err != nil {
return err
}
mut.Lock()
logger.Info("Initializing test store in pool", mlog.String("datasource", *settings.DataSource))
entries[*settings.DataSource] = &TestPoolEntry{
Store: sqlStore,
Settings: settings,
}
mut.Unlock()
return nil
})
}
if err := eg.Wait(); err != nil {
return nil, err
}
return &TestPool{
entries: entries,
logger: logger,
}, nil
}
func (p *TestPool) Get(t testing.TB) *TestPoolEntry {
p.mut.Lock()
defer p.mut.Unlock()
p.logger.Info("Getting from test store pool", mlog.Int("poolSize", len(p.entries)))
var poolEntry *TestPoolEntry
for _, entry := range p.entries {
poolEntry = entry
delete(p.entries, *entry.Settings.DataSource)
break
}
// No more stores available in the pool
if poolEntry == nil {
return nil
}
p.logger.Info("Got store from pool", mlog.String("datasource", *poolEntry.Settings.DataSource), mlog.Int("poolSize", len(p.entries)))
dataSource := *poolEntry.Settings.DataSource
// Return store to pool on test cleanup
t.Cleanup(func() {
p.mut.Lock()
defer p.mut.Unlock()
p.logger.Info("Returning to test store pool", mlog.String("datasource", dataSource), mlog.Int("poolSize", len(p.entries)))
p.entries[dataSource] = poolEntry
})
return poolEntry
}
func (p *TestPool) Close() {
p.mut.Lock()
defer p.mut.Unlock()
var wg sync.WaitGroup
wg.Add(len(p.entries))
for _, entry := range p.entries {
go func() {
defer wg.Done()
entry.Store.Close()
storetest.CleanupSqlSettings(entry.Settings)
}()
}
wg.Wait()
}