Skip to content

Commit

Permalink
Merge pull request #50 from ali-ince/1.7-pass-access-mode-tests
Browse files Browse the repository at this point in the history
Add tests for passing access mode
  • Loading branch information
ali-ince authored Mar 6, 2019
2 parents 72f1ee3 + 1af7d99 commit 9a2fa53
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 397 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Windows doesn't provide `pkg-config`, so have it installed by following [these i

#### Binaries

We're now providing _**experimental**_ binaries for `Linux`, `MacOS` and `Windows` [here](https://github.com/neo4j-drivers/seabolt/releases). Please remember that `OpenSSL` is still a requirement for all of these systems. In order to link seabolt statically make sure you have static OpenSSL libraries, too.
We're now providing _**experimental**_ binaries for `Linux`, `MacOS` and `Windows` [here](https://github.com/neo4j-drivers/seabolt/releases). Please remember that `OpenSSL` is still a requirement for all of these systems.

Linux packages are being built on `Ubuntu 16.04` system and generated artifacts contain symbol references/absolute paths to dependent static/dynamic libraries which are only applicable to `Ubuntu 16.04` package versions/file system layout. _**It may be better to compile seabolt from scratch if you are on a different Linux distribution or version.**_
Static linking against seabolt is only supported on **_Linux_** and **_MacOS_** at this time, and in order to get it working make sure you have static OpenSSL libraries, too.

#### Source

Expand All @@ -56,6 +56,8 @@ Add the driver with `go get github.com/neo4j/neo4j-go-driver/neo4j`

We provide `seabolt_static` build tag to support static linking against seabolt and its dependencies. You can just pass `--tags seabolt_static` to your `go` toolset (like `go build --tags seabolt_static`) for your project and the output will not have any runtime dependency to `seabolt` and `openssl`.

_**Static linking is currently not supported on Windows.**_

## Setting RPATH on Linux/MacOS

Both Linux and MacOS dynamic loader support `RPATH` entries into executables so that they can locate their dependent shared libraries based on those entries. To have a `RUNPATH` entry to be added to your executable, you can pass `-ldflags "-r $(pkg-config --variable=libdir seabolt17)"` to your `go` toolset (like `go build -ldflags "-r $(pkg-config --variable=libdir seabolt17)"`) and it will add an `RPATH` entry to your executable that points to the location where seabolt shared library resides.
Expand Down
17 changes: 8 additions & 9 deletions neo4j/test-stub/control/boltstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import (
"path"
"runtime"
"sync/atomic"
"testing"
"time"

. "github.com/onsi/ginkgo"
)

// StubServer represents a running instance of a scripted bolt stub server
Expand Down Expand Up @@ -69,20 +68,20 @@ func (server *StubServer) exitError() string {
}

// NewStubServer launches the stub server on the given port with the given script
func NewStubServer(port int, script string) *StubServer {
func NewStubServer(t *testing.T, port int, script string) *StubServer {
var testScriptsDir = os.TempDir()

if _, file, _, ok := runtime.Caller(1); ok {
testScriptsDir = path.Join(path.Dir(file), "scripts")
}

if len(testScriptsDir) == 0 {
Fail("unable to locate bolt stub script folder")
t.Fatalf("unable to locate bolt stub script folder")
}

testScriptFile := path.Join(testScriptsDir, script)
if _, err := os.Stat(testScriptFile); os.IsNotExist(err) {
Fail(fmt.Sprintf("unable to locate bolt stub script file at '%s'", testScriptFile))
t.Fatalf("unable to locate bolt stub script file at '%s'", testScriptFile)
}

cmd := exec.Command("boltstub", fmt.Sprint(port), testScriptFile)
Expand Down Expand Up @@ -132,17 +131,17 @@ func NewStubServer(port int, script string) *StubServer {
}

if server.exited() && server.exitError() != "" {
Fail(server.exitError())
t.Fatalf(server.exitError())
}

Fail(fmt.Sprintf("unable to open a connection to boltstub server at [:%d]", server.port))
t.Fatalf("unable to open a connection to boltstub server at [:%d]", server.port)

return nil
}

// Finished expects the stub server to already be exited returns whether it was exited
// with success code. If the process did not exit as expected, it returns false (or fails the test)
func (server *StubServer) Finished() bool {
func (server *StubServer) Finished(t *testing.T) bool {
// Close our initial connection to make the stub server exit
if server.conn != nil {
server.conn.Close()
Expand All @@ -167,7 +166,7 @@ func (server *StubServer) Finished() bool {

// Check if an error occurred
if server.exitError() != "" {
Fail(server.exitError())
t.Fatalf(server.exitError())
}

return true
Expand Down
171 changes: 46 additions & 125 deletions neo4j/test-stub/disconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,134 +21,55 @@ package test_stub

import (
"path"
"testing"

"github.com/neo4j-drivers/gobolt"
"github.com/neo4j/neo4j-go-driver/neo4j/test-stub/control"
"github.com/neo4j/neo4j-go-driver/neo4j/utils/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
)

var _ = Describe("Disconnect", func() {
var stub *control.StubServer

AfterEach(func() {
if stub != nil {
Expect(stub.Finished()).To(BeTrue())

stub.Close()
}
})

Context("V1", func() {
It("should return error when server disconnects after INIT", func() {
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_after_init.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
})

It("should return error when server disconnects after RUN", func() {
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_on_run.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
})

It("should return error when server disconnects after PULL_ALL", func() {
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_on_pull_all.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
})
})

Context("V3", func() {
It("should return error when server disconnects after HELLO", func() {
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_after_hello.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
})

It("should return error when server disconnects after RUN", func() {
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_on_run.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
})

It("should return error when server disconnects after PULL_ALL", func() {
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_on_pull_all.script"))

driver := newDriver("bolt://localhost:9001")
defer driver.Close()

session := createSession(driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
Expect(err).To(BeNil())

summary, err := result.Consume()

Expect(err).To(test.BeServiceUnavailableError())
Expect(summary).To(BeNil())
func Test_Disconnect(t *testing.T) {
var cases = []struct {
name string
protocol string
}{
{"V1", "v1"},
{"V3", "v3"},
}

for _, testCase := range cases {
t.Run(testCase.name, func(t *testing.T) {
var verifyServiceUnavailable = func(t *testing.T, script string) {
stub := control.NewStubServer(t, 9001, path.Join(testCase.protocol, script))
defer stub.Finished(t)

driver := newDriver(t, "bolt://localhost:9001")
defer driver.Close()

session := createWriteSession(t, driver)
defer session.Close()

result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
assert.NoError(t, err)

summary, err := result.Consume()
assert.Error(t, err)
assert.True(t, gobolt.IsServiceUnavailable(err))
assert.Nil(t, summary)
}

t.Run("shouldReturnErrorWhenServerDisconnectsAfterInit", func(t *testing.T) {
verifyServiceUnavailable(t, "disconnect_after_login.script")
})

t.Run("shouldReturnErrorWhenServerDisconnectsAfterRun", func(t *testing.T) {
verifyServiceUnavailable(t, "disconnect_on_run.script")
})

t.Run("shouldReturnErrorWhenServerDisconnectsAfterPullAll", func(t *testing.T) {
verifyServiceUnavailable(t, "disconnect_on_pull_all.script")
})
})
})
}

})
}
40 changes: 0 additions & 40 deletions neo4j/test-stub/ginkgo_test.go

This file was deleted.

Loading

0 comments on commit 9a2fa53

Please sign in to comment.