on xenial help sign in
Improve findChild calls inside tryCompareFunction

findChild has a timeout retry since a while ago. This means that if we have a findChild inside a tryCompareFunction the retries multiply and it takes around 30 minutes for the tryCompareFunction to fail if the findChild is failing, so what we do is set the timeout of findChild to 0 In other cases we just had a tryCompareFunction that made sure the findChild after it would succeed, since now findChild has a retry mechanism we can just remove that tryCompareFunction altogether

commited1a770bd9ea178f4887578f3238bf7b5a088a9a authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 30 Aug 2016, 11:33 (10 years ago) parent4de859c
10 files changed+28−47
tests/qmltests/Components/tst_Carousel.qml−1 tests/qmltests/Components/tst_Lockscreen.qml+1−2 tests/qmltests/Dash/Previews/tst_Preview.qml−2 tests/qmltests/Dash/Previews/tst_PreviewHeader.qml−4 tests/qmltests/Dash/tst_CardTool.qml+4−4 tests/qmltests/Dash/tst_Dash.qml+8−8 tests/qmltests/Dash/tst_DashContent.qml+5−7 tests/qmltests/Dash/tst_GenericScopeView.qml+9−15 tests/qmltests/Panel/tst_IndicatorPage.qml−2 tests/qmltests/tst_ShellWithPin.qml+1−2
tests/qmltests/Components/tst_Carousel.qml−1
@@ -268,7 +268,6 @@ Item {
268268
269269 function test_activate() {
270270 var carouselList = findChild(carousel, "listView");
271− tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
272271 var carouselItem = findChild(carousel, "carouselDelegate3")
273272 verify(carouselItem, "Could not find delegate");
274273
tests/qmltests/Components/tst_Lockscreen.qml+1−2
@@ -422,7 +422,6 @@ Rectangle {
422422 function test_infoPopup() {
423423 verify(findChild(root, "infoPopup") === null);
424424 lockscreen.showInfoPopup("foo", "bar");
425− tryCompareFunction(function() { return findChild(root, "infoPopup") !== null}, true);
426425
427426 var infoPopup = findChild(root, "infoPopup");
428427 compare(infoPopup.title, "foo");
@@ -434,7 +433,7 @@ Rectangle {
434433 var okButton = findChild(root, "infoPopupOkButton");
435434 mouseClick(okButton);
436435
437− tryCompareFunction(function() { return findChild(root, "infoPopup") === null}, true);
436+ tryCompareFunction(function() { return findChild(root, "infoPopup", 0 /* timeout */) === null}, true);
438437
439438 tryCompare(signalSpy, "count", 1);
440439 }
tests/qmltests/Dash/Previews/tst_Preview.qml−2
@@ -78,7 +78,6 @@ Rectangle {
7878
7979 function test_containOnFocus() {
8080 waitForRendering(preview);
81− tryCompareFunction(function () { return findChild(preview, "widget-10") != null }, true);
8281 var widget = findChild(preview, "widget-10");
8382
8483 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
@@ -94,7 +93,6 @@ Rectangle {
9493
9594 function test_containOnGrow() {
9695 waitForRendering(preview);
97− tryCompareFunction(function () { return findChild(preview, "widget-13") != null }, true);
9896 var widget = findChild(preview, "widget-13");
9997
10098 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
tests/qmltests/Dash/Previews/tst_PreviewHeader.qml−4
@@ -116,7 +116,6 @@ Rectangle {
116116
117117 tryCompare(testCase.mascotShapeLoader, "visible", data.loaderVisible);
118118 if (data.loaderVisible) {
119− tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
120119 var mascot = findChild(previewHeader, "mascotShape")
121120 tryCompare(mascot, "visible", data.visible);
122121 }
@@ -165,20 +164,17 @@ Rectangle {
165164
166165 function test_fallback() {
167166 previewHeader.widgetData = brokenheaderjson;
168− tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
169167 var mascot = findChild(previewHeader, "mascotShape");
170168 compare(mascot.visible, false);
171169
172170 previewHeader.widgetData = {};
173171 previewHeader.widgetData = fallbackheaderjson;
174− tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
175172 var mascot = findChild(previewHeader, "mascotShape");
176173 tryCompare(mascot, "visible", true);
177174 tryCompare(mascot.source, "status", Image.Ready);
178175
179176 previewHeader.widgetData = {};
180177 previewHeader.widgetData = emptyfallbackheaderjson;
181− tryCompareFunction(function() { return findChild(previewHeader, "mascotShape") != null }, true);
182178 var mascot = findChild(previewHeader, "mascotShape");
183179 tryCompare(mascot, "visible", true);
184180 tryCompare(mascot.source, "status", Image.Ready);
tests/qmltests/Dash/tst_CardTool.qml+4−4
@@ -339,22 +339,22 @@ Rectangle {
339339 function test_card_title_alignment(data) {
340340 selector.selectedIndex = data.index;
341341
342− tryCompareFunction(function() { return findChild(internalCard, "titleLabel").horizontalAlignment == Text.AlignLeft; }, true);
342+ tryCompareFunction(function() { return findChild(internalCard, "titleLabel", 0 /* timeout */).horizontalAlignment == Text.AlignLeft; }, true);
343343
344344 cardTool.components['title'] = { "field": "title", "align": "center" };
345345 cardTool.componentsChanged();
346346
347− tryCompareFunction(function() { return findChild(internalCard, "titleLabel").horizontalAlignment == data.value; }, true);
347+ tryCompareFunction(function() { return findChild(internalCard, "titleLabel", 0 /* timeout */).horizontalAlignment == data.value; }, true);
348348
349349 cardTool.components['title'] = { "field": "title" };
350350 cardTool.componentsChanged();
351351
352− tryCompareFunction(function() { return findChild(internalCard, "titleLabel").horizontalAlignment == data.value; }, true);
352+ tryCompareFunction(function() { return findChild(internalCard, "titleLabel", 0 /* timeout */).horizontalAlignment == data.value; }, true);
353353
354354 cardTool.components['title'] = { "field": "title", "align": "left" };
355355 cardTool.componentsChanged();
356356
357− tryCompareFunction(function() { return findChild(internalCard, "titleLabel").horizontalAlignment == Text.AlignLeft; }, true);
357+ tryCompareFunction(function() { return findChild(internalCard, "titleLabel", 0 /* timeout */).horizontalAlignment == Text.AlignLeft; }, true);
358358 }
359359
360360 function test_categoryLayout_data() {
tests/qmltests/Dash/tst_Dash.qml+8−8
@@ -76,7 +76,7 @@ Item {
7676 var genericScopeView = dashContentList.currentItem;
7777 var categoryListView = findChild(genericScopeView, "categoryListView");
7878 tryCompareFunction(function() {
79− var category = findChild(genericScopeView, categoryName);
79+ var category = findChild(genericScopeView, categoryName, 0 /* timeout */);
8080 if (category && category.y > 0 && category.y < genericScopeView.height) return true;
8181 touchFlick(genericScopeView, genericScopeView.width/2, units.gu(20),
8282 genericScopeView.width/2, genericScopeView.y)
@@ -84,7 +84,7 @@ Item {
8484 return false;
8585 }, true);
8686
87− tryCompareFunction(function() { return findChild(genericScopeView, "delegate0") !== null; }, true);
87+ tryCompareFunction(function() { return findChild(genericScopeView, "delegate0", 0 /* timeout */) !== null; }, true);
8888 return findChild(genericScopeView, categoryName);
8989 }
9090
@@ -94,9 +94,9 @@ Item {
9494 if (category === undefined) category = 0;
9595 if (delegate === undefined) delegate = 0;
9696 tryCompareFunction(function() {
97− var cardGrid = findChild(genericScopeView, "dashCategory"+category);
97+ var cardGrid = findChild(genericScopeView, "dashCategory"+category, 0 /* timeout */);
9898 if (cardGrid != null) {
99− var tile = findChild(cardGrid, "delegate"+delegate);
99+ var tile = findChild(cardGrid, "delegate"+delegate, 0 /* timeout */);
100100 return tile != null;
101101 }
102102 return false;
@@ -473,9 +473,9 @@ Item {
473473 compare(dashContentList.currentItem.scopeId, "MockScope1");
474474
475475 tryCompareFunction(function() {
476− var cardGrid = findChild(dashContentList, "dashCategory0");
476+ var cardGrid = findChild(dashContentList, "dashCategory0", 0 /* timeout */);
477477 if (cardGrid != null) {
478− var tile = findChild(cardGrid, "delegate0");
478+ var tile = findChild(cardGrid, "delegate0", 0 /* timeout */);
479479 return tile != null;
480480 }
481481 return false;
@@ -520,9 +520,9 @@ Item {
520520 var categoryListView = findChild(dashTempScopeItem, "categoryListView");
521521 categoryListView.positionAtBeginning();
522522 tryCompareFunction(function() {
523− var cardGrid = findChild(dashTempScopeItem, "dashCategory0");
523+ var cardGrid = findChild(dashTempScopeItem, "dashCategory0", 0 /* timeout */);
524524 if (cardGrid != null) {
525− var tile = findChild(cardGrid, "delegate0");
525+ var tile = findChild(cardGrid, "delegate0", 0 /* timeout */);
526526 return tile != null;
527527 }
528528 return false;
tests/qmltests/Dash/tst_DashContent.qml+5−7
@@ -261,11 +261,11 @@ Item {
261261
262262 function test_carouselAspectRatio() {
263263 tryCompareFunction(function() {
264− var scope = findChild(dashContent, "scopeLoader0");
264+ var scope = findChild(dashContent, "scopeLoader0", 0 /* timeout */);
265265 if (scope != null) {
266− var dashCategory1 = findChild(scope, "dashCategory1");
266+ var dashCategory1 = findChild(scope, "dashCategory1", 0 /* timeout */);
267267 if (dashCategory1 != null) {
268− var tile = findChild(dashCategory1, "carouselDelegate1");
268+ var tile = findChild(dashCategory1, "carouselDelegate1", 0 /* timeout */);
269269 return tile != null;
270270 }
271271 }
@@ -282,7 +282,6 @@ Item {
282282
283283 function test_mainNavigation() {
284284 var dashContentList = findChild(dashContent, "dashContentList");
285− tryCompareFunction(function() { return findChild(dashContentList.currentItem, "dashNavigation") != null; }, true);
286285 var dashNavigation = findChild(dashContentList.currentItem, "dashNavigation");
287286 var peExtraPanel = findChild(dashContentList.currentItem, "peExtraPanel");
288287 var searchButton = findChild(dashContentList.currentItem, "search_button");
@@ -405,7 +404,6 @@ Item {
405404
406405 function goToSecondLevel() {
407406 var dashContentList = findChild(dashContent, "dashContentList");
408− tryCompareFunction(function() { return findChild(dashContentList.currentItem, "dashNavigation") != null; }, true);
409407 var dashNavigation = findChild(dashContentList.currentItem, "dashNavigation");
410408 var peExtraPanel = findChild(dashContentList.currentItem, "peExtraPanel");
411409 var searchButton = findChild(dashContentList.currentItem, "search_button");
@@ -580,7 +578,7 @@ Item {
580578
581579 function test_primaryFilter() {
582580 var dashContentList = findChild(dashContent, "dashContentList");
583− tryCompareFunction(function() { return findChild(dashContentList.currentItem, "dashNavigation") != null; }, true);
581+ tryCompareFunction(function() { return findChild(dashContentList.currentItem, "dashNavigation", 0 /* timeout */) != null; }, true);
584582 dashContentList.currentItem.item.scope.setHasNavigation(false);
585583 var peExtraPanel = findChild(dashContentList.currentItem, "peExtraPanel");
586584 var searchButton = findChild(dashContentList.currentItem, "search_button");
@@ -589,7 +587,7 @@ Item {
589587 mouseClick(searchButton);
590588 tryCompare(peExtraPanel, "visible", true);
591589
592− tryCompareFunction(function() { return findChild(peExtraPanel, "OSF3") != null; }, true);
590+ tryCompareFunction(function() { return findChild(peExtraPanel, "OSF3", 0 /* timeout */) != null; }, true);
593591 }
594592
595593 function test_searchHint() {
tests/qmltests/Dash/tst_GenericScopeView.qml+9−15
@@ -92,7 +92,7 @@ Item {
9292 function scrollToCategory(categoryName) {
9393 var categoryListView = findChild(genericScopeView, "categoryListView");
9494 tryCompareFunction(function() {
95− var category = findChild(genericScopeView, categoryName);
95+ var category = findChild(genericScopeView, categoryName, 0 /* timeout */);
9696 if (category && category.y > 0 && category.y < genericScopeView.height) return true;
9797 touchFlick(genericScopeView, genericScopeView.width/2, units.gu(20),
9898 genericScopeView.width/2, genericScopeView.y)
@@ -100,7 +100,7 @@ Item {
100100 return false;
101101 }, true);
102102
103− tryCompareFunction(function() { return findChild(genericScopeView, "delegate0") !== null; }, true);
103+ tryCompareFunction(function() { return findChild(genericScopeView, "delegate0", 0 /* timeout */) !== null; }, true);
104104 return findChild(genericScopeView, categoryName);
105105 }
106106
@@ -163,7 +163,7 @@ Item {
163163 }
164164
165165 function test_expand_collapse() {
166− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader0") != null; }, true);
166+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader0", 0 /* timeout */) != null; }, true);
167167
168168 var category = findChild(genericScopeView, "dashCategory0")
169169 var seeAll = findChild(category, "seeAll")
@@ -184,7 +184,7 @@ Item {
184184
185185 function test_expand_expand_collapse() {
186186 // wait for the item to be there
187− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader2") != null; }, true);
187+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader2", 0 /* timeout */) != null; }, true);
188188
189189 var categoryListView = findChild(genericScopeView, "categoryListView");
190190 categoryListView.contentY = categoryListView.height;
@@ -212,7 +212,6 @@ Item {
212212 }
213213
214214 function test_headerLink() {
215− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader1") != null; }, true);
216215 var header = findChild(genericScopeView, "dashSectionHeader1");
217216
218217 spy.target = genericScopeView.scope;
@@ -231,7 +230,7 @@ Item {
231230 categoryListView.contentY = categoryListView.height * 2;
232231
233232 // wait for the item to be there
234− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader4") != null; }, true);
233+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader4", 0 /* timeout */) != null; }, true);
235234
236235 var categoryView = findChild(genericScopeView, "dashCategory4");
237236 verify(categoryView, "Can't find the category view.");
@@ -243,7 +242,6 @@ Item {
243242 }
244243
245244 function test_narrow_delegate_ranges_expand() {
246− tryCompareFunction(function() { return findChild(genericScopeView, "dashCategory0") !== null; }, true);
247245 var category = findChild(genericScopeView, "dashCategory0")
248246 tryCompare(category, "expanded", false);
249247
@@ -275,7 +273,6 @@ Item {
275273 function test_single_category_expansion() {
276274 genericScopeView.scope = scopes.getScope(3);
277275
278− tryCompareFunction(function() { return findChild(genericScopeView, "dashCategory0") != undefined; }, true);
279276 var category = findChild(genericScopeView, "dashCategory0")
280277 compare(category.expandable, false, "Only category should not be expandable.");
281278
@@ -289,9 +286,9 @@ Item {
289286 if (category === undefined) category = 0;
290287 if (delegate === undefined) delegate = 0;
291288 tryCompareFunction(function() {
292− var cardGrid = findChild(genericScopeView, "dashCategory"+category);
289+ var cardGrid = findChild(genericScopeView, "dashCategory"+category, 0 /* timeout */);
293290 if (cardGrid != null) {
294− var tile = findChild(cardGrid, "delegate"+delegate);
291+ var tile = findChild(cardGrid, "delegate"+delegate, 0 /* timeout */);
295292 return tile != null;
296293 }
297294 return false;
@@ -332,9 +329,9 @@ Item {
332329 genericScopeView.scope = scopes.getScope("NullPreviewScope");
333330
334331 tryCompareFunction(function() {
335− var cardGrid = findChild(genericScopeView, 0);
332+ var cardGrid = findChild(genericScopeView, 0, 0 /* timeout */);
336333 if (cardGrid != null) {
337− var tile = findChild(cardGrid, 0);
334+ var tile = findChild(cardGrid, 0, 0 /* timeout */);
338335 return tile != null;
339336 }
340337 return false;
@@ -385,7 +382,6 @@ Item {
385382
386383 tryCompare(testCase.subPageLoader, "open", false);
387384
388− tryCompareFunction(function() { return findChild(category, "delegate1") != null; }, true);
389385 var tile = findChild(category, "delegate1");
390386
391387 mouseClick(tile);
@@ -487,7 +483,6 @@ Item {
487483
488484 scrollToEnd();
489485
490− tryCompareFunction(function() { return findChild(genericScopeView, "dashCategory1") !== null; }, true);
491486 var category1 = findChild(genericScopeView, "dashCategory1")
492487 var seeAll1 = findChild(category1, "seeAll")
493488 verify(category1.expandable);
@@ -669,7 +664,6 @@ Item {
669664 function test_carousel_borderSource() {
670665 var category = scrollToCategory("dashCategory1");
671666 var tile = findChild(category, "carouselDelegate0");
672− tryCompareFunction(function() { return findChild(tile, "artShapeLoader") !== null; }, true);
673667 var artShapeLoader = findChild(tile, "artShapeLoader");
674668 var shape = findChildsByType(artShapeLoader, "UCUbuntuShape");
675669 compare(shape.borderSource, undefined);
tests/qmltests/Panel/tst_IndicatorPage.qml−2
@@ -177,8 +177,6 @@ Item {
177177 initializeMenuData(fullMenuData);
178178
179179 var menuId = "menu"+data.remove
180−
181− tryCompareFunction(function() { return findChild(page, menuId) !== null;}, true);
182180 var menu = findChild(page, menuId);
183181
184182 menu.menuSelected();
tests/qmltests/tst_ShellWithPin.qml+1−2
@@ -363,12 +363,11 @@ Item {
363363
364364 enterPin("1111")
365365 enterPin("1111")
366− tryCompareFunction(function() {return findChild(root, "infoPopup") !== null}, true)
367366
368367 var dialog = findChild(root, "infoPopup")
369368 var button = findChild(dialog, "infoPopupOkButton")
370369 tap(button)
371− tryCompareFunction(function() {return findChild(root, "infoPopup")}, null)
370+ tryCompareFunction(function() {return findChild(root, "infoPopup", 0 /* timeout */)}, null)
372371
373372 tryCompare(resetSpy, "count", 0)
374373 enterPin("1111")