Skip to content

Commit

Permalink
fix server activation test
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Jan 2, 2025
1 parent a9ffd4a commit 78da3c1
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"
"time"

"github.com/go-pkgz/fileutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -219,22 +218,18 @@ func Test_activateServerOnly(t *testing.T) {

opts.Files.SamplesDataPath, opts.Files.DynamicDataPath = t.TempDir(), t.TempDir()

// copy sample files from testdata
err := fileutils.CopyFile("../data/ham-samples.txt", path.Join(opts.Files.SamplesDataPath, "ham-samples.txt"))
// write some sample files
fh, err := os.Create(path.Join(opts.Files.SamplesDataPath, "spam-samples.txt"))
require.NoError(t, err)
err = fileutils.CopyFile("../data/spam-samples.txt", path.Join(opts.Files.SamplesDataPath, "spam-samples.txt"))
_, err = fh.WriteString("spam1\nspam2\nspam3\n")
require.NoError(t, err)
fh.Close()

db, err := storage.NewSqliteDB(path.Join(opts.Files.DynamicDataPath, "tg-spam.db"), "gr1")
fh, err = os.Create(path.Join(opts.Files.SamplesDataPath, "ham-samples.txt"))
require.NoError(t, err)
defer db.Close()

samplesStore, err := storage.NewSamples(ctx, db)
require.NoError(t, err)
err = samplesStore.Add(ctx, storage.SampleTypeSpam, storage.SampleOriginPreset, "spam1")
require.NoError(t, err)
err = samplesStore.Add(ctx, storage.SampleTypeHam, storage.SampleOriginPreset, "ham1")
_, err = fh.WriteString("ham1\nham2\nham3\n")
require.NoError(t, err)
fh.Close()

done := make(chan struct{})
go func() {
Expand All @@ -251,7 +246,7 @@ func Test_activateServerOnly(t *testing.T) {
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}, time.Second*10, time.Millisecond*50, "server did not start")
}, time.Second*5, time.Millisecond*100, "server did not start")

resp, err := http.Get("http://localhost:9988/ping")
require.NoError(t, err)
Expand Down

0 comments on commit 78da3c1

Please sign in to comment.