-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for timeout and lifetime checks
- Loading branch information
Showing
7 changed files
with
333 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,4 +71,3 @@ func wrapAddressResolverOrNil(addressResolver ServerAddressResolver) gobolt.UrlA | |
return result | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package test_integration | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/neo4j/neo4j-go-driver/neo4j" | ||
"github.com/neo4j/neo4j-go-driver/neo4j/test-integration/control" | ||
"github.com/neo4j/neo4j-go-driver/neo4j/test-integration/utils" | ||
"github.com/neo4j/neo4j-go-driver/neo4j/utils/test" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Timeout and Lifetime", func() { | ||
var err error | ||
var log *utils.MemoryLogging | ||
var server *control.SingleInstance | ||
|
||
BeforeEach(func() { | ||
log = &utils.MemoryLogging{} | ||
|
||
server, err = control.EnsureSingleInstance() | ||
Expect(err).To(BeNil()) | ||
Expect(server).NotTo(BeNil()) | ||
}) | ||
|
||
It("should error when ConnectionAcquisitionTimeout is hit", func() { | ||
var err error | ||
var driver neo4j.Driver | ||
var session1, session2 neo4j.Session | ||
|
||
driver, err = neo4j.NewDriver(server.BoltUri(), server.AuthToken(), server.Config(), func(config *neo4j.Config) { | ||
config.Log = log | ||
config.ConnectionAcquisitionTimeout = 1 * time.Second | ||
config.MaxConnectionPoolSize = 1 | ||
}) | ||
Expect(err).To(BeNil()) | ||
Expect(driver).NotTo(BeNil()) | ||
defer driver.Close() | ||
|
||
session1, _ = newSessionAndTx(driver, neo4j.AccessModeRead) | ||
defer session1.Close() | ||
|
||
session2, err = driver.Session(neo4j.AccessModeRead) | ||
Expect(err).To(BeNil()) | ||
Expect(session2).NotTo(BeNil()) | ||
defer session2.Close() | ||
|
||
_, err = session2.Run("RETURN 1", nil) | ||
Expect(err).To(test.BeConnectorErrorWithCode(0x601)) | ||
}) | ||
|
||
It("should close connection when MaxConnectionLifetime is hit", func() { | ||
var err error | ||
var driver neo4j.Driver | ||
var session1, session2 neo4j.Session | ||
|
||
driver, err = neo4j.NewDriver(server.BoltUri(), server.AuthToken(), server.Config(), func(config *neo4j.Config) { | ||
config.Log = log | ||
config.MaxConnectionLifetime = 5 * time.Second | ||
config.MaxConnectionPoolSize = 1 | ||
}) | ||
Expect(err).To(BeNil()) | ||
Expect(driver).NotTo(BeNil()) | ||
defer driver.Close() | ||
|
||
session1, _ = newSessionAndTx(driver, neo4j.AccessModeRead) | ||
time.Sleep(5 * time.Second) | ||
session1.Close() | ||
|
||
session2, _ = newSessionAndTx(driver, neo4j.AccessModeRead) | ||
defer session2.Close() | ||
|
||
Expect(log.Infos).Should(ContainElement(ContainSubstring("reached its maximum lifetime"))) | ||
}) | ||
|
||
It("should timeout connection when SocketConnectTimeout is hit", func() { | ||
var err error | ||
var driver neo4j.Driver | ||
var session neo4j.Session | ||
|
||
driver, err = neo4j.NewDriver("bolt://192.168.0.0:8080", server.AuthToken(), server.Config(), func(config *neo4j.Config) { | ||
config.Log = log | ||
config.SocketConnectTimeout = 5 * time.Second | ||
}) | ||
Expect(err).To(BeNil()) | ||
Expect(driver).NotTo(BeNil()) | ||
defer driver.Close() | ||
|
||
session = newSession(driver, neo4j.AccessModeRead) | ||
defer session.Close() | ||
|
||
_, err = session.BeginTransaction() | ||
Expect(err).To(test.BeConnectorErrorWithCode(6)) | ||
}) | ||
|
||
It("should timeout receive when SocketReceiveTimeout is hit on encrypted connection", func() { | ||
var err error | ||
var driver neo4j.Driver | ||
var session neo4j.Session | ||
var result neo4j.Result | ||
|
||
driver, err = neo4j.NewDriver(server.BoltUri(), server.AuthToken(), server.Config(), func(config *neo4j.Config) { | ||
config.Log = log | ||
config.SocketReceiveTimeout = 1 * time.Second | ||
}) | ||
Expect(err).To(BeNil()) | ||
Expect(driver).NotTo(BeNil()) | ||
defer driver.Close() | ||
|
||
session = newSession(driver, neo4j.AccessModeRead) | ||
defer session.Close() | ||
|
||
result, err = session.Run("UNWIND RANGE(1,100000000) AS N RETURN SUM(N)", nil) | ||
Expect(err).To(BeNil()) | ||
|
||
_, err = result.Consume() | ||
Expect(err).To(test.BeConnectorErrorWithCode(6)) | ||
}) | ||
|
||
It("should timeout receive when SocketReceiveTimeout is hit on plaintext connection", func() { | ||
var err error | ||
var driver neo4j.Driver | ||
var session neo4j.Session | ||
var result neo4j.Result | ||
|
||
driver, err = neo4j.NewDriver(server.BoltUri(), server.AuthToken(), server.Config(), func(config *neo4j.Config) { | ||
config.Encrypted = false | ||
config.Log = log | ||
config.SocketReceiveTimeout = 1 * time.Second | ||
}) | ||
Expect(err).To(BeNil()) | ||
Expect(driver).NotTo(BeNil()) | ||
defer driver.Close() | ||
|
||
session = newSession(driver, neo4j.AccessModeRead) | ||
defer session.Close() | ||
|
||
result, err = session.Run("UNWIND RANGE(1,100000000) AS N RETURN SUM(N)", nil) | ||
Expect(err).To(BeNil()) | ||
|
||
_, err = result.Consume() | ||
Expect(err).To(test.BeConnectorErrorWithCode(6)) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import "fmt" | ||
|
||
type MemoryLogging struct { | ||
Errors []string | ||
Warnings []string | ||
Infos []string | ||
Debugs []string | ||
} | ||
|
||
func (log *MemoryLogging) ErrorEnabled() bool { | ||
return true | ||
} | ||
|
||
func (log *MemoryLogging) WarningEnabled() bool { | ||
return true | ||
} | ||
|
||
func (log *MemoryLogging) InfoEnabled() bool { | ||
return true | ||
} | ||
|
||
func (log *MemoryLogging) DebugEnabled() bool { | ||
return true | ||
} | ||
|
||
func (log *MemoryLogging) Errorf(message string, args ...interface{}) { | ||
log.Errors = append(log.Errors, fmt.Sprintf(message, args...)) | ||
} | ||
|
||
func (log *MemoryLogging) Warningf(message string, args ...interface{}) { | ||
log.Warnings = append(log.Warnings, fmt.Sprintf(message, args...)) | ||
} | ||
|
||
func (log *MemoryLogging) Infof(message string, args ...interface{}) { | ||
log.Infos = append(log.Infos, fmt.Sprintf(message, args...)) | ||
} | ||
|
||
func (log *MemoryLogging) Debugf(message string, args ...interface{}) { | ||
log.Debugs = append(log.Debugs, fmt.Sprintf(message, args...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,4 +66,4 @@ func logLevel() neo4j.LogLevel { | |
} | ||
|
||
return neo4j.ERROR | ||
} | ||
} |