@@ -114,12 +114,17 @@ public void testRemoveTreeMatches() throws Exception {
114114 private void consumeEvents (FileSearchPage page ) {
115115 IJobManager manager = Job .getJobManager ();
116116 while (manager .find (page ).length > 0 ) {
117- Display . getDefault (). readAndDispatch ();
117+ consumeEvents ();
118118 }
119+ consumeEvents ();
119120 }
120121
121122 private void consumeEvents () {
122123 while (Display .getDefault ().readAndDispatch ()) {
124+ try {
125+ Thread .sleep (20 );
126+ } catch (InterruptedException e ) {
127+ }
123128 }
124129 }
125130
@@ -141,26 +146,27 @@ public void testTableNavigation() {
141146 page .setLayout (AbstractTextSearchViewPage .FLAG_LAYOUT_FLAT );
142147 Table table = ((TableViewer ) page .getViewer ()).getTable ();
143148
144- consumeEvents ();
149+ consumeEvents (page );
145150
146151 // select the first element.
147152 table .setSelection (0 );
153+ consumeEvents (page );
148154 table .showSelection ();
149155
150- consumeEvents ();
156+ consumeEvents (page );
151157 // back from first match, goto last
152158 page .gotoPreviousMatch ();
153159
154- consumeEvents ();
160+ consumeEvents (page );
155161
156- assertEquals (1 , table .getSelectionCount ());
157- assertEquals (table .getItemCount ()- 1 , table .getSelectionIndex ());
162+ assertEquals (1 , table .getSelectionCount (), "Selection count is wrong" );
163+ assertEquals (table .getItemCount () - 1 , table .getSelectionIndex (), "Selection index is wrong" );
158164
159165 // and forward again, to the first match.
160166 page .gotoNextMatch ();
161167
162- consumeEvents ();
163- assertEquals (1 , table .getSelectionCount ());
164- assertEquals (0 , table .getSelectionIndex ());
168+ consumeEvents (page );
169+ assertEquals (1 , table .getSelectionCount (), "Selection count is wrong" );
170+ assertEquals (0 , table .getSelectionIndex (), "Selection index is wrong" );
165171}
166172}
0 commit comments