From 727a67b8b2bacc5f566aa1e642ce49530e7a015d Mon Sep 17 00:00:00 2001 From: Florent Biville <445792+fbiville@users.noreply.github.com> Date: Tue, 10 May 2022 14:09:31 +0200 Subject: [PATCH] Update VerifyConnectivity to rely on GetServerInfo This is what all 5.x drivers do. --- neo4j/driver_with_context.go | 32 +++++++++++++------------------- testkit-backend/backend.go | 22 ++++++++++++++++------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/neo4j/driver_with_context.go b/neo4j/driver_with_context.go index 2fdada39..62a077c9 100644 --- a/neo4j/driver_with_context.go +++ b/neo4j/driver_with_context.go @@ -273,28 +273,10 @@ func (d *driverWithContext) NewSession(config SessionConfig) SessionWithContext } func (d *driverWithContext) VerifyConnectivity(ctx context.Context) error { - session := d.NewSession(SessionConfig{AccessMode: AccessModeRead}) - defer session.Close(ctx) - result, err := session.Run(ctx, "RETURN 1 AS n", nil) - if err != nil { - return err - } - _, err = result.Consume(ctx) + _, err := d.GetServerInfo(ctx) return err } -func (d *driverWithContext) Close(ctx context.Context) error { - d.mut.Lock() - defer d.mut.Unlock() - // Safeguard against closing more than once - if d.pool != nil { - d.pool.Close(ctx) - } - d.pool = nil - d.log.Infof(log.Driver, d.logId, "Closed") - return nil -} - func (d *driverWithContext) IsEncrypted() bool { return !d.connector.SkipEncryption } @@ -306,3 +288,15 @@ func (d *driverWithContext) GetServerInfo(ctx context.Context) (_ ServerInfo, er }() return session.getServerInfo(ctx) } + +func (d *driverWithContext) Close(ctx context.Context) error { + d.mut.Lock() + defer d.mut.Unlock() + // Safeguard against closing more than once + if d.pool != nil { + d.pool.Close(ctx) + } + d.pool = nil + d.log.Infof(log.Driver, d.logId, "Closed") + return nil +} diff --git a/testkit-backend/backend.go b/testkit-backend/backend.go index 95035728..565eba4f 100644 --- a/testkit-backend/backend.go +++ b/testkit-backend/backend.go @@ -715,6 +715,14 @@ func (b *backend) handleRequest(req map[string]interface{}) { "encrypted": driver.IsEncrypted(), }) + case "VerifyConnectivity": + driverId := data["driverId"].(string) + if err := b.drivers[driverId].VerifyConnectivity(ctx); err != nil { + b.writeError(err) + return + } + b.writeResponse("Driver", map[string]interface{}{"id": driverId}) + case "GetFeatures": b.writeResponse("FeatureList", map[string]interface{}{ "features": []string{ @@ -723,6 +731,7 @@ func (b *backend) handleRequest(req map[string]interface{}) { "Feature:API:ConnectionAcquisitionTimeout", "Feature:API:Driver:GetServerInfo", "Feature:API:Driver.IsEncrypted", + "Feature:API:Driver.VerifyConnectivity", "Feature:API:Liveness.Check", "Feature:API:Result.List", "Feature:API:Result.Peek", @@ -921,11 +930,12 @@ func testSkips() map[string]string { "stub.iteration.test_result_scope.TestResultScope.*": "Results are always valid but don't return records when out of scope", "stub.*.test_0_timeout": "Driver omits 0 as tx timeout value", "stub.*.test_negative_timeout": "Driver omits negative tx timeout values", - "stub.routing.*.*.test_should_request_rt_from_all_initial_routers_until_successful_on_unknown_failure": "Add DNS resolver TestKit message and connection timeout support", - "stub.routing.*.*.test_should_request_rt_from_all_initial_routers_until_successful_on_authorization_expired": "Add DNS resolver TestKit message and connection timeout support", - "stub.summary.test_summary.TestSummary.test_server_info": "Needs some kind of server address DNS resolution", - "stub.summary.test_summary.TestSummary.test_invalid_query_type": "Driver does not verify query type returned from server.", - "stub.routing.*.test_should_drop_connections_failing_liveness_check": "Needs support for GetConnectionPoolMetrics", - "stub.connectivity_check.test_get_server_info.TestGetServerInfo.test_routing_fail_when_no_reader_are_available": "Won't fix - Go driver retries routing table when no readers are available", + "stub.routing.*.*.test_should_request_rt_from_all_initial_routers_until_successful_on_unknown_failure": "Add DNS resolver TestKit message and connection timeout support", + "stub.routing.*.*.test_should_request_rt_from_all_initial_routers_until_successful_on_authorization_expired": "Add DNS resolver TestKit message and connection timeout support", + "stub.summary.test_summary.TestSummary.test_server_info": "Needs some kind of server address DNS resolution", + "stub.summary.test_summary.TestSummary.test_invalid_query_type": "Driver does not verify query type returned from server.", + "stub.routing.*.test_should_drop_connections_failing_liveness_check": "Needs support for GetConnectionPoolMetrics", + "stub.connectivity_check.test_get_server_info.TestGetServerInfo.test_routing_fail_when_no_reader_are_available": "Won't fix - Go driver retries routing table when no readers are available", + "stub.connectivity_check.test_verify_connectivity.TestVerifyConnectivity.test_routing_fail_when_no_reader_are_available": "Won't fix - Go driver retries routing table when no readers are available", } }