Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/sanity: Use a single grpc connection #98

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/csi-sanity/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_NAME := csi-sanity
VER :=$(shell git describe)
VER :=$(shell git describe --tag --dirty)
RELEASEVER := $(shell git describe --abbrev=0)
BRANCH := $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
SHA := $(shell git rev-parse --short HEAD)
Expand Down
18 changes: 18 additions & 0 deletions hack/_apitest/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package apitest

import (
"os"
"testing"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
)

func TestMyDriver(t *testing.T) {
config := &sanity.Config{
TargetPath: os.TempDir() + "/csi",
StagingPath: os.TempDir() + "/csi",
Address: "/tmp/e2e-csi-sanity.sock",
}

sanity.Test(t, config)
}
33 changes: 33 additions & 0 deletions hack/_embedded/embedded_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package embedded

import (
"os"
"testing"

"github.com/kubernetes-csi/csi-test/pkg/sanity"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestMyDriverGinkgo(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Sanity Test Suite")
}

var _ = Describe("MyCSIDriver", func() {
Context("Config A", func() {
config := &sanity.Config{
TargetPath: os.TempDir() + "/csi",
StagingPath: os.TempDir() + "/csi",
Address: "/tmp/e2e-csi-sanity.sock",
}

BeforeEach(func() {})

AfterEach(func() {})

Describe("CSI Driver Test Suite", func() {
sanity.GinkgoTest(config)
})
})
})
22 changes: 22 additions & 0 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ runTestWithCreds()
fi
}

runTestAPI()
{
CSI_ENDPOINT=$1 ./bin/mock &
local pid=$!

GOCACHE=off go test -v ./hack/_apitest/api_test.go; ret=$?

if [ $ret -ne 0 ] ; then
exit $ret
fi

GOCACHE=off go test -v ./hack/_embedded/embedded_test.go; ret=$?
kill -9 $pid

if [ $ret -ne 0 ] ; then
exit $ret
fi
}

go build -o bin/mock ./mock || exit 1

cd cmd/csi-sanity
Expand All @@ -47,4 +66,7 @@ rm -f $UDS
runTestWithCreds "${UDS}" "${UDS}"
rm -f $UDS

runTestAPI "${UDS}"
rm -f $UDS

exit 0
13 changes: 7 additions & 6 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

"github.com/container-storage-interface/spec/lib/go/csi/v0"

"strconv"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
)

const (
Expand Down Expand Up @@ -86,8 +87,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
)

BeforeEach(func() {
c = csi.NewControllerClient(sc.Conn)
n = csi.NewNodeClient(sc.Conn)
c = csi.NewControllerClient(conn)
n = csi.NewNodeClient(conn)

cl = &Cleanup{
NodeClient: n,
Expand Down Expand Up @@ -1098,7 +1099,7 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *SanityConte
)

BeforeEach(func() {
c = csi.NewControllerClient(sc.Conn)
c = csi.NewControllerClient(conn)

if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS) {
Skip("ListSnapshots not supported")
Expand Down Expand Up @@ -1392,7 +1393,7 @@ var _ = DescribeSanity("DeleteSnapshot [Controller Server]", func(sc *SanityCont
)

BeforeEach(func() {
c = csi.NewControllerClient(sc.Conn)
c = csi.NewControllerClient(conn)

if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT) {
Skip("DeleteSnapshot not supported")
Expand Down Expand Up @@ -1455,7 +1456,7 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont
)

BeforeEach(func() {
c = csi.NewControllerClient(sc.Conn)
c = csi.NewControllerClient(conn)

if !isControllerCapabilitySupported(c, csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT) {
Skip("CreateSnapshot not supported")
Expand Down
2 changes: 1 addition & 1 deletion pkg/sanity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = DescribeSanity("Identity Service", func(sc *SanityContext) {
)

BeforeEach(func() {
c = csi.NewIdentityClient(sc.Conn)
c = csi.NewIdentityClient(conn)
})

Describe("GetPluginCapabilities", func() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
)

BeforeEach(func() {
c = csi.NewNodeClient(sc.Conn)
s = csi.NewControllerClient(sc.Conn)
c = csi.NewNodeClient(conn)
s = csi.NewControllerClient(conn)

controllerPublishSupported = isControllerCapabilitySupported(
s,
Expand Down Expand Up @@ -145,7 +145,7 @@ var _ = DescribeSanity("Node Service", func(sc *SanityContext) {
)

BeforeEach(func() {
i = csi.NewIdentityClient(sc.Conn)
i = csi.NewIdentityClient(conn)
accessibilityConstraintSupported = isPluginCapabilitySupported(i, csi.PluginCapability_Service_ACCESSIBILITY_CONSTRAINTS)
})

Expand Down
27 changes: 18 additions & 9 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,44 @@ type Config struct {
// gets initialized before each test block runs.
type SanityContext struct {
Config *Config
Conn *grpc.ClientConn
Secrets *CSISecrets
}

var (
conn *grpc.ClientConn
address string
)

// Test will test the CSI driver at the specified address by
// setting up a Ginkgo suite and running it.
func Test(t *testing.T, reqConfig *Config) {
sc := &SanityContext{
Config: reqConfig,
}

address = sc.Config.Address
registerTestsInGinkgo(sc)
RegisterFailHandler(Fail)
RunSpecs(t, "CSI Driver Test Suite")
}

var _ = BeforeSuite(func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @pohly 's change required these not to be set. Please check with him over slack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now it makes sense why this was removed. Embedding this test in an existing ginkgo setup with existing global BeforeSuite and AfterSuite fails to run. Maybe it's better to go with connection retry approach. The examples in ginkgo docs create multiple DB connections for each test case to avoid test pollution.

I don't have much experience with ginkgo. @pohly what do you think? Maybe there's some other better way to fix this?

var err error
By("connecting to CSI driver")
conn, err = utils.Connect(address)
Expect(err).NotTo(HaveOccurred())
})

var _ = AfterSuite(func() {
conn.Close()
})

func GinkgoTest(reqConfig *Config) {
sc := &SanityContext{
Config: reqConfig,
}

address = sc.Config.Address
registerTestsInGinkgo(sc)
}

Expand All @@ -92,10 +109,6 @@ func (sc *SanityContext) setup() {
sc.Secrets = &CSISecrets{}
}

By("connecting to CSI driver")
sc.Conn, err = utils.Connect(sc.Config.Address)
Expect(err).NotTo(HaveOccurred())

By("creating mount and staging directories")
err = createMountTargetLocation(sc.Config.TargetPath)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -106,10 +119,6 @@ func (sc *SanityContext) setup() {
}

func (sc *SanityContext) teardown() {
if sc.Conn != nil {
sc.Conn.Close()
sc.Conn = nil
}
}

func createMountTargetLocation(targetPath string) error {
Expand Down