Skip to content

Commit

Permalink
Update VerifyConnectivity to rely on GetServerInfo
Browse files Browse the repository at this point in the history
This is what all 5.x drivers do.
  • Loading branch information
fbiville authored May 10, 2022
1 parent c751bc5 commit 727a67b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
32 changes: 13 additions & 19 deletions neo4j/driver_with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
22 changes: 16 additions & 6 deletions testkit-backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
}
}

0 comments on commit 727a67b

Please sign in to comment.