OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library browser; | 4 library browser; |
5 | 5 |
6 import "dart:async"; | 6 import "dart:async"; |
7 import "dart:convert" show LineSplitter, UTF8; | 7 import "dart:convert" show LineSplitter, UTF8; |
8 import "dart:core"; | 8 import "dart:core"; |
9 import "dart:io"; | 9 import "dart:io"; |
10 | 10 |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 734 |
735 /** | 735 /** |
736 * Describes the current state of a browser used for testing. | 736 * Describes the current state of a browser used for testing. |
737 */ | 737 */ |
738 class BrowserTestingStatus { | 738 class BrowserTestingStatus { |
739 Browser browser; | 739 Browser browser; |
740 BrowserTest currentTest; | 740 BrowserTest currentTest; |
741 | 741 |
742 // This is currently not used for anything except for error reporting. | 742 // This is currently not used for anything except for error reporting. |
743 // Given the usefulness of this in debugging issues this should not be | 743 // Given the usefulness of this in debugging issues this should not be |
744 // removed even when we have really stable system. | 744 // removed even when we have a really stable system. |
745 BrowserTest lastTest; | 745 BrowserTest lastTest; |
746 bool timeout = false; | 746 bool timeout = false; |
747 Timer nextTestTimeout; | 747 Timer nextTestTimeout; |
| 748 Stopwatch timeSinceRestart = new Stopwatch(); |
748 | 749 |
749 BrowserTestingStatus(Browser this.browser); | 750 BrowserTestingStatus(Browser this.browser); |
750 } | 751 } |
751 | 752 |
752 | 753 |
753 /** | 754 /** |
754 * Describes a single test to be run int the browser. | 755 * Describes a single test to be run in the browser. |
755 */ | 756 */ |
756 class BrowserTest { | 757 class BrowserTest { |
757 // TODO(ricow): Add timeout callback instead of the string passing hack. | 758 // TODO(ricow): Add timeout callback instead of the string passing hack. |
758 Function doneCallback; | 759 Function doneCallback; |
759 String url; | 760 String url; |
760 int timeout; | 761 int timeout; |
761 String lastKnownMessage = ''; | 762 String lastKnownMessage = ''; |
762 Stopwatch stopwatch; | 763 Stopwatch stopwatch; |
763 | 764 |
764 // This might be null | 765 // This might be null |
(...skipping 30 matching lines...) Expand all Loading... |
795 | 796 |
796 /** | 797 /** |
797 * Encapsulates all the functionality for running tests in browsers. | 798 * Encapsulates all the functionality for running tests in browsers. |
798 * The interface is rather simple. After starting, the runner tests | 799 * The interface is rather simple. After starting, the runner tests |
799 * are simply added to the queue and a the supplied callbacks are called | 800 * are simply added to the queue and a the supplied callbacks are called |
800 * whenever a test completes. | 801 * whenever a test completes. |
801 */ | 802 */ |
802 class BrowserTestRunner { | 803 class BrowserTestRunner { |
803 static const int MAX_NEXT_TEST_TIMEOUTS = 10; | 804 static const int MAX_NEXT_TEST_TIMEOUTS = 10; |
804 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 60); | 805 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 60); |
| 806 static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); |
805 | 807 |
806 final Map globalConfiguration; | 808 final Map globalConfiguration; |
807 final bool checkedMode; // needed for dartium | 809 final bool checkedMode; // needed for dartium |
808 | 810 |
809 String localIp; | 811 String localIp; |
810 String browserName; | 812 String browserName; |
811 int maxNumBrowsers; | 813 int maxNumBrowsers; |
812 // Used to send back logs from the browser (start, stop etc) | 814 // Used to send back logs from the browser (start, stop etc) |
813 Function logger; | 815 Function logger; |
814 int browserIdCount = 0; | 816 int browserIdCount = 0; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 testingServer.nextTestCallBack = getNextTest; | 859 testingServer.nextTestCallBack = getNextTest; |
858 return getBrowsers().then((browsers) { | 860 return getBrowsers().then((browsers) { |
859 var futures = []; | 861 var futures = []; |
860 for (var browser in browsers) { | 862 for (var browser in browsers) { |
861 var url = testingServer.getDriverUrl(browser.id); | 863 var url = testingServer.getDriverUrl(browser.id); |
862 var future = browser.start(url).then((success) { | 864 var future = browser.start(url).then((success) { |
863 if (success) { | 865 if (success) { |
864 var status = new BrowserTestingStatus(browser); | 866 var status = new BrowserTestingStatus(browser); |
865 browserStatus[browser.id] = status; | 867 browserStatus[browser.id] = status; |
866 status.nextTestTimeout = createNextTestTimer(status); | 868 status.nextTestTimeout = createNextTestTimer(status); |
| 869 status.timeSinceRestart.start(); |
867 } | 870 } |
868 return success; | 871 return success; |
869 }); | 872 }); |
870 futures.add(future); | 873 futures.add(future); |
871 } | 874 } |
872 return Future.wait(futures).then((values) { | 875 return Future.wait(futures).then((values) { |
873 return !values.contains(false); | 876 return !values.contains(false); |
874 }); | 877 }); |
875 }); | 878 }); |
876 }); | 879 }); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 } else { | 1044 } else { |
1042 browserStatus.remove(id); | 1045 browserStatus.remove(id); |
1043 browser = getInstance(); | 1046 browser = getInstance(); |
1044 new_id = "BROWSER$browserIdCount"; | 1047 new_id = "BROWSER$browserIdCount"; |
1045 browserIdCount++; | 1048 browserIdCount++; |
1046 } | 1049 } |
1047 browser.id = new_id; | 1050 browser.id = new_id; |
1048 var status = new BrowserTestingStatus(browser); | 1051 var status = new BrowserTestingStatus(browser); |
1049 browserStatus[new_id] = status; | 1052 browserStatus[new_id] = status; |
1050 status.nextTestTimeout = createNextTestTimer(status); | 1053 status.nextTestTimeout = createNextTestTimer(status); |
| 1054 status.timeSinceRestart.start(); |
1051 browser.start(testingServer.getDriverUrl(new_id)).then((success) { | 1055 browser.start(testingServer.getDriverUrl(new_id)).then((success) { |
1052 // We may have started terminating in the mean time. | 1056 // We may have started terminating in the mean time. |
1053 if (underTermination) { | 1057 if (underTermination) { |
1054 if (status.nextTestTimeout != null) { | 1058 if (status.nextTestTimeout != null) { |
1055 status.nextTestTimeout.cancel(); | 1059 status.nextTestTimeout.cancel(); |
1056 status.nextTestTimeout = null; | 1060 status.nextTestTimeout = null; |
1057 } | 1061 } |
1058 browser.close().then((success) { | 1062 browser.close().then((success) { |
1059 // We should never hit this, print it out. | 1063 // We should never hit this, print it out. |
1060 if (!success) { | 1064 if (!success) { |
(...skipping 15 matching lines...) Expand all Loading... |
1076 if (status == null) return null; | 1080 if (status == null) return null; |
1077 if (status.nextTestTimeout != null) { | 1081 if (status.nextTestTimeout != null) { |
1078 status.nextTestTimeout.cancel(); | 1082 status.nextTestTimeout.cancel(); |
1079 status.nextTestTimeout = null; | 1083 status.nextTestTimeout = null; |
1080 } | 1084 } |
1081 if (testQueue.isEmpty) return null; | 1085 if (testQueue.isEmpty) return null; |
1082 | 1086 |
1083 // We are currently terminating this browser, don't start a new test. | 1087 // We are currently terminating this browser, don't start a new test. |
1084 if (status.timeout) return null; | 1088 if (status.timeout) return null; |
1085 | 1089 |
| 1090 // Restart content_shell and dartium on Android if they have been |
| 1091 // running for longer than RESTART_BROWSER_INTERVAL. The tests have |
| 1092 // had flaky timeouts, and this may help. |
| 1093 if ((browserName == 'ContentShellOnAndroid' || |
| 1094 browserName == 'DartiumOnAndroid' ) && |
| 1095 status.timeSinceRestart.elapsed > RESTART_BROWSER_INTERVAL) { |
| 1096 var id = status.browser.id; |
| 1097 status.browser.close().then((_) { |
| 1098 // We don't want to start a new browser if we are terminating. |
| 1099 if (underTermination) return; |
| 1100 restartBrowser(id); |
| 1101 }); |
| 1102 // Don't send a test to the browser we are restarting. |
| 1103 return null; |
| 1104 } |
| 1105 |
1086 BrowserTest test = testQueue.removeLast(); | 1106 BrowserTest test = testQueue.removeLast(); |
1087 if (status.currentTest == null) { | 1107 if (status.currentTest == null) { |
1088 status.currentTest = test; | 1108 status.currentTest = test; |
1089 status.currentTest.lastKnownMessage = ''; | 1109 status.currentTest.lastKnownMessage = ''; |
1090 } else { | 1110 } else { |
1091 // TODO(ricow): Handle this better. | 1111 // TODO(ricow): Handle this better. |
1092 print("Browser requested next test before reporting previous result"); | 1112 print("Browser requested next test before reporting previous result"); |
1093 print("This happened for browser $browserId"); | 1113 print("This happened for browser $browserId"); |
1094 print("Old test was: ${status.currentTest.url}"); | 1114 print("Old test was: ${status.currentTest.url}"); |
1095 print("The test before that was: ${status.lastTest.url}"); | 1115 print("The test before that was: ${status.lastTest.url}"); |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 Dart test driver, number of tests: <div id="number"></div><br> | 1577 Dart test driver, number of tests: <div id="number"></div><br> |
1558 Currently executing: <div id="currently_executing"></div><br> | 1578 Currently executing: <div id="currently_executing"></div><br> |
1559 Unhandled error: <div id="unhandled_error"></div> | 1579 Unhandled error: <div id="unhandled_error"></div> |
1560 <iframe id="embedded_iframe"></iframe> | 1580 <iframe id="embedded_iframe"></iframe> |
1561 </body> | 1581 </body> |
1562 </html> | 1582 </html> |
1563 """; | 1583 """; |
1564 return driverContent; | 1584 return driverContent; |
1565 } | 1585 } |
1566 } | 1586 } |
OLD | NEW |