@@ -44,6 +44,9 @@ pub enum Error {
44
44
#[ error( "geoip lookup failed" ) ]
45
45
GeoipLookup ( #[ source] test_rpc:: Error ) ,
46
46
47
+ #[ error( "DNS lookup failed" ) ]
48
+ DnsLookup ( #[ source] std:: io:: Error ) ,
49
+
47
50
#[ error( "Found running daemon unexpectedly" ) ]
48
51
DaemonRunning ,
49
52
@@ -76,13 +79,61 @@ pub fn get_tests() -> Vec<&'static TestMetadata> {
76
79
77
80
/// Restore settings to the defaults.
78
81
pub async fn cleanup_after_test (
79
- rpc : ServiceClient ,
82
+ mut rpc : ServiceClient ,
80
83
rpc_provider : & RpcClientProvider ,
81
84
) -> anyhow:: Result < ( ) > {
82
85
log:: debug!( "Cleaning up daemon in test cleanup" ) ;
83
86
// Check if daemon should be restarted.
84
- // TODO: The deamon needs to be up and running after this line.
85
- restart_daemon ( rpc) . await ?;
87
+ // TODO: Move this shizzle up one level?
88
+ // TODO: The daemon needs to be up and running after this line.
89
+ if let Err ( daemon_restart_error) = restart_daemon ( & rpc) . await {
90
+ match daemon_restart_error {
91
+ // Something went wrong in the communication between test-manager <-> test-runner.
92
+ Error :: Rpc ( rpc_error) => {
93
+ log:: warn!( "Could not restart the daemon due to RPC-error: {rpc_error}" ) ;
94
+ // TODO: Try to create a new gRPC client. Need to move this logic up one level to
95
+ // do this.
96
+
97
+ // Restart the test-runner
98
+ // HACK: Accomplish this by restarting the virtual machine. This should not be
99
+ // necessary.
100
+ rpc. reboot ( ) . await . inspect_err ( |_| {
101
+ log:: error!( "Failed to reboot test runner virtual machine!" ) ;
102
+ } ) ?;
103
+ rpc. reset_daemon_environment ( ) . await . inspect_err ( |daemon_restart_failure| {
104
+ log:: warn!( "Rebooting the test runner virtual machine did not work: {daemon_restart_failure}" )
105
+ } ) ?;
106
+ }
107
+ // Something wen't wrong in the daemon.
108
+ daemon_error @ ( Error :: DaemonNotRunning
109
+ | Error :: Daemon ( _)
110
+ | Error :: UnexpectedErrorState ( _)
111
+ | Error :: ManagementInterface ( _) ) => {
112
+ log:: warn!( "Could not restart daemon due to daemon error: {daemon_error}" ) ;
113
+ log:: warn!( "Rebooting the test runner virtual machine" ) ;
114
+ // First, reboot the test-runner VM.
115
+ rpc. reboot ( ) . await . inspect_err ( |_| {
116
+ log:: error!( "Failed to reboot test runner virtual machine!" ) ;
117
+ } ) ?;
118
+ if let Err ( daemon_restart_failure) = rpc. reset_daemon_environment ( ) . await {
119
+ log:: warn!( "Rebooting the test runner virtual machine did not work: {daemon_restart_failure}" ) ;
120
+ log:: warn!( "Reinstalling the app" ) ;
121
+ // TODO: If rebooting the VM did not work, try to re-install the app.
122
+ }
123
+ }
124
+ // We don't really care about these errors in this context.
125
+ non_fatal @ ( Error :: DaemonRunning
126
+ | Error :: GeoipLookup ( _)
127
+ | Error :: DnsLookup ( _)
128
+ | Error :: MissingGuiTest ) => {
129
+ log:: warn!( "Could not restart daemon due to non-fatal error: {non_fatal}" ) ;
130
+ log:: warn!( "Restarting dameon one more time" ) ;
131
+ rpc. reset_daemon_environment ( ) . await ?;
132
+ }
133
+ #[ cfg( target_os = "macos" ) ]
134
+ Other ( _) => todo ! ( "Remove this variant, we can't handle this error properly" ) ,
135
+ }
136
+ }
86
137
let mut mullvad_client = rpc_provider. new_client ( ) . await ;
87
138
88
139
helpers:: disconnect_and_wait ( & mut mullvad_client) . await ?;
@@ -197,7 +248,7 @@ pub async fn cleanup_after_test(
197
248
/// If the daemon was started with non-standard environment variables, subsequent tests may break
198
249
/// due to assuming a default configuration. In that case, reset the environment variables and
199
250
/// restart.
200
- async fn restart_daemon ( rpc : ServiceClient ) -> anyhow :: Result < ( ) > {
251
+ async fn restart_daemon ( rpc : & ServiceClient ) -> Result < ( ) , Error > {
201
252
let current_env = rpc. get_daemon_environment ( ) . await ?;
202
253
let default_env = get_app_env ( ) . await ?;
203
254
if current_env != default_env {
0 commit comments