worker: ensure connections are closed in local state on controller fail (#1369)
This backports some test work that is being added in #1340 to assert that the worker is actually marking connections closed in its *local* state on a failure to contact the controller. This was missed in #1357 during some late-stage refactoring. Summary of the changes: * If we can't actually contact the controller during connection closure to mark the connections as closed, we actually construct a "fake" response that just simply includes a closed state for all connections requested. This is then used to update the local connection state. * Added a 3 second timeout to the CloseConnection request to the controller to ensure the call to close connections completed in a timely manner and did not hang indefinitely. Testing enhancements: * Added a new helper in TestHelper called LookupSession that allows the lookup of a session from the worker's internal session state. * This is used in the new ExpectConnectionStateOnWorker check in the E2E test, which is part of a larger amount of enhancements to the E2E test that are coming in #1340. * Added a ConnectionStatusFromProtoVal helper function to the session package to allow the conversion of protobuf connection status values to their higher-level counterparts; essentially it is a reverse of ConnectionStatus.ProtoVal. This is used in some of our tests (with more coming in #1340) to just help with keeping things more idiomatic. Finally, there is some minor error refactoring, and we also change the timeout on internal status and connection close requests to the controller to 5 seconds.
This commit is contained in:
1 parent
b3a74584ca
commit
48e55f156a
7 files changed
+359
-29
No files matched your search
@@ -19,9 +19,10 @@ const (
|
||||
type ConnectionStatus string
|
||||
|
||||
const (
|
||||
StatusAuthorized ConnectionStatus = "authorized"
|
||||
StatusConnected ConnectionStatus = "connected"
|
||||
StatusClosed ConnectionStatus = "closed"
|
||||
StatusAuthorized ConnectionStatus = "authorized"
|
||||
StatusConnected ConnectionStatus = "connected"
|
||||
StatusClosed ConnectionStatus = "closed"
|
||||
StatusUnspecified ConnectionStatus = "unspecified" // Utility state not valid in the DB
|
||||
)
|
||||
|
||||
// String representation of the state's status
|
||||
@@ -42,6 +43,20 @@ func (s ConnectionStatus) ProtoVal() workerpbs.CONNECTIONSTATUS {
|
||||
return workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_UNSPECIFIED
|
||||
}
|
||||
|
||||
// ConnectionStatusFromProtoVal is the reverse of
|
||||
// ConnectionStatus.ProtoVal.
|
||||
func ConnectionStatusFromProtoVal(s workerpbs.CONNECTIONSTATUS) ConnectionStatus {
|
||||
switch s {
|
||||
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_AUTHORIZED:
|
||||
return StatusAuthorized
|
||||
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CONNECTED:
|
||||
return StatusConnected
|
||||
case workerpbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED:
|
||||
return StatusClosed
|
||||
}
|
||||
return StatusUnspecified
|
||||
}
|
||||
|
||||
// ConnectionState of the state of the connection
|
||||
type ConnectionState struct {
|
||||
// ConnectionId is used to access the state via an API
|
||||
|
||||
Reference in new issue
Block a user