test: close servers

This commit is contained in:
Kevin Franklin Kim 2024-11-25 22:23:12 +01:00
parent ea920005e9
commit e50df5eaf9
No known key found for this signature in database
3 changed files with 17 additions and 25 deletions

View File

@ -27,12 +27,12 @@ doc:
.PHONY: test
## Run tests
test:
@go test -coverprofile=coverage.out -race -json ./... | gotestfmt
@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -race -json ./... | gotestfmt
.PHONY: test.update
## Run tests and update snapshots
test.update:
@go test -update -coverprofile=coverage.out -race -json ./... | gotestfmt
@GO_TEST_TAGS=-skip go test -update -coverprofile=coverage.out -race -json ./... | gotestfmt
.PHONY: lint
## Run linter
@ -61,7 +61,7 @@ install:
## Build binary
build:
@mkdir -p bin
@go build -o bin/sesamy main.go
@go build -o bin/contentserver main.go
## === Utils ===

View File

@ -18,7 +18,7 @@ import (
)
func TestUpdate(t *testing.T) {
testWithClients(t, func(c *client.Client) {
testWithClients(t, func(t *testing.T, c *client.Client) {
response, err := c.Update(context.TODO())
require.NoError(t, err)
require.True(t, response.Success, "update has to return .Sucesss true")
@ -28,7 +28,7 @@ func TestUpdate(t *testing.T) {
}
func TestGetURIs(t *testing.T) {
testWithClients(t, func(c *client.Client) {
testWithClients(t, func(t *testing.T, c *client.Client) {
request := mock.MakeValidURIsRequest()
uriMap, err := c.GetURIs(context.TODO(), request.Dimension, request.IDs)
time.Sleep(100 * time.Millisecond)
@ -38,7 +38,7 @@ func TestGetURIs(t *testing.T) {
}
func TestGetRepo(t *testing.T) {
testWithClients(t, func(c *client.Client) {
testWithClients(t, func(t *testing.T, c *client.Client) {
r, err := c.GetRepo(context.TODO())
require.NoError(t, err)
if assert.NotEmpty(t, r, "received empty JSON from GetRepo") {
@ -48,7 +48,7 @@ func TestGetRepo(t *testing.T) {
}
func TestGetNodes(t *testing.T) {
testWithClients(t, func(c *client.Client) {
testWithClients(t, func(t *testing.T, c *client.Client) {
nodesRequest := mock.MakeNodesRequest()
nodes, err := c.GetNodes(context.TODO(), nodesRequest.Env, nodesRequest.Nodes)
require.NoError(t, err)
@ -67,20 +67,12 @@ func TestGetNodes(t *testing.T) {
}
func TestGetContent(t *testing.T) {
testWithClients(t, func(c *client.Client) {
testWithClients(t, func(t *testing.T, c *client.Client) {
request := mock.MakeValidContentRequest()
response, err := c.GetContent(context.TODO(), request)
if err != nil {
t.Fatal("unexpected err", err)
}
if request.URI != response.URI {
dump(t, request)
dump(t, response)
t.Fatal("uri mismatch")
}
if response.Status != content.StatusOk {
t.Fatal("unexpected status")
}
require.NoError(t, err)
assert.Equal(t, request.URI, response.URI)
assert.Equal(t, response.Status, content.StatusOk)
})
}
@ -121,7 +113,7 @@ func benchmarkClientAndServerGetContent(tb testing.TB, numGroups, numCalls int,
wg.Wait()
}
func testWithClients(t *testing.T, testFunc func(c *client.Client)) {
func testWithClients(t *testing.T, testFunc func(t *testing.T, c *client.Client)) {
t.Helper()
l := zaptest.NewLogger(t)
httpRepoServer := initHTTPRepoServer(t, l)
@ -129,12 +121,13 @@ func testWithClients(t *testing.T, testFunc func(c *client.Client)) {
httpClient := newHTTPClient(t, httpRepoServer)
socketClient := newSocketClient(t, socketRepoServer.Addr().String())
defer func() {
httpRepoServer.Close()
socketRepoServer.Close()
httpClient.Close()
socketClient.Close()
socketRepoServer.Close()
}()
testFunc(httpClient)
testFunc(socketClient)
testFunc(t, httpClient)
testFunc(t, socketClient)
}
func initRepo(tb testing.TB, l *zap.Logger) *repo.Repo {

View File

@ -2,7 +2,6 @@ package repo
import (
"context"
"strings"
"testing"
"time"
@ -124,7 +123,7 @@ func TestLoadRepoDuplicateUris(t *testing.T) {
response := r.Update()
require.False(t, response.Success, "there are duplicates, this repo update should have failed")
assert.True(t, strings.Contains(response.ErrorMessage, "update dimension"), "error message not as expected: "+response.ErrorMessage)
assert.Contains(t, response.ErrorMessage, "update dimension")
}
func TestDimensionHygiene(t *testing.T) {