cheets_GTS: Overriding "all_done" before no-test check.

In crrev.com/c/2471118 I enabled a workaround to mark some
harmless failures as PASS, but it wasn't fully working,
in case of the harmless error resulted in executing 0 tests.

This CL exchanges the ordering to enable the workaround
on the corner case as well.

BUG=b:170799343
TEST=cheets_GTS.8.0_r1.GtsIncrementalInstall

Change-Id: I241f71aca26eaa02cddfc9fdf3a95813cdf15cf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2480302
Tested-by: Kazuhiro Inaba <kinaba@chromium.org>
Auto-Submit: Kazuhiro Inaba <kinaba@chromium.org>
Commit-Queue: Jiyoun Ha <jiyounha@chromium.org>
Reviewed-by: Jiyoun Ha <jiyounha@chromium.org>
(cherry picked from commit df046c5a87b71af204c3644d7a931da919b53fad)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2484026
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Commit-Queue: Kazuhiro Inaba <kinaba@chromium.org>
diff --git a/server/cros/tradefed/tradefed_test.py b/server/cros/tradefed/tradefed_test.py
index 5701bfd..792054b 100644
--- a/server/cros/tradefed/tradefed_test.py
+++ b/server/cros/tradefed/tradefed_test.py
@@ -1324,6 +1324,15 @@
                 self.summary += msg
                 logging.info('RESULT: %s %s', msg, result)
 
+                # Overwrite last_all_done if the executed test count is equal
+                # to the known test count of the job.
+                if (not last_all_done and executable_test_count != None and
+                    (last_passed + last_failed in executable_test_count)):
+                    logging.warning('Overwriting all_done as True, since the '
+                                    'explicitly set executable_test_count '
+                                    'tests have run.')
+                    last_all_done = True
+
                 # Check for no-test modules. We use the "all_done" indicator
                 # provided by list_results to decide if there are outstanding
                 # modules to iterate over (similar to missing tests just on a
@@ -1346,14 +1355,10 @@
                         current_login.need_reboot()
                     continue
 
+                # After the no-test check, commit the pass/fail count.
                 waived = last_waived
-                session_id, passed, failed, all_done  = result
-                if (not all_done and executable_test_count != None and
-                        (passed + failed in executable_test_count)):
-                    logging.warning('Overwriting all_done as True, since the '
-                                    'explicitly set executable_test_count '
-                                    'tests have run.')
-                    all_done = True
+                session_id, passed, failed, all_done =\
+                    last_session_id, last_passed, last_failed, last_all_done
 
                 # Check if all the tests passed.
                 if failed <= waived and all_done: