test: workaround race in the tests with zaptest package

Looks like `zaptest` package when used from the goroutine (like in gRPC
server) results in a potential data race on test tear down.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Andrey Smirnov 2021-09-28 23:05:09 +03:00
parent 9c67fde759
commit ecdd7757fb
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD

View File

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/aes" "crypto/aes"
"log"
"net" "net"
"testing" "testing"
"time" "time"
@ -23,11 +24,11 @@ import (
"github.com/talos-systems/discovery-service/pkg/client" "github.com/talos-systems/discovery-service/pkg/client"
"github.com/talos-systems/discovery-service/pkg/server" "github.com/talos-systems/discovery-service/pkg/server"
"github.com/talos-systems/go-retry/retry" "github.com/talos-systems/go-retry/retry"
"go.uber.org/zap/zaptest"
"google.golang.org/grpc" "google.golang.org/grpc"
"inet.af/netaddr" "inet.af/netaddr"
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster" clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
"github.com/talos-systems/talos/pkg/logging"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine" "github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/proto" "github.com/talos-systems/talos/pkg/machinery/proto"
"github.com/talos-systems/talos/pkg/resources/cluster" "github.com/talos-systems/talos/pkg/resources/cluster"
@ -44,7 +45,7 @@ func setupServer(t *testing.T) (address string) {
lis, err := net.Listen("tcp", "localhost:0") lis, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err) require.NoError(t, err)
logger := zaptest.NewLogger(t) logger := logging.Wrap(log.Writer())
serverOptions := []grpc.ServerOption{ serverOptions := []grpc.ServerOption{
grpc_middleware.WithUnaryServerChain( grpc_middleware.WithUnaryServerChain(
@ -128,7 +129,7 @@ func (suite *DiscoveryServiceSuite) TestReconcile() {
defer cliCtxCancel() defer cliCtxCancel()
go func() { go func() {
errCh <- cli.Run(cliCtx, zaptest.NewLogger(suite.T()), notifyCh) errCh <- cli.Run(cliCtx, logging.Wrap(log.Writer()), notifyCh)
}() }()
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry( suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(