Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slowness with custom event queue #4

Closed
gschrader opened this issue Sep 27, 2012 · 0 comments
Closed

Slowness with custom event queue #4

gschrader opened this issue Sep 27, 2012 · 0 comments

Comments

@gschrader
Copy link

When you have a custom event queue then any call to waitForIdle will wait until the idleTimeout because the following:

while (eventQueue.peekEvent() != null) 

peekEvent returns an InvocationEvent caused by a timer blinking the caret in the textfield.

Here is a testcase that illustrates the issue:

package org.fest.swing.core;

import org.fest.swing.test.recorder.KeyRecorder;
import org.fest.swing.timing.Condition;
import org.junit.After;
import org.junit.Test;

import java.awt.*;
import java.util.concurrent.Executors;

import static java.awt.event.KeyEvent.*;
import static org.fest.swing.timing.Pause.pause;
import static org.fest.swing.timing.Timeout.timeout;
import static org.fest.util.Arrays.array;

/**
 * Tests for issue with slow waitForIdle with a custom event queue
 *
 * @author Glen Schrader
 * @author Alex Ruiz
 */
public class CustomEventQueue_Test extends BasicRobot_TestCase {
    private CustomEventQueue newEventQueue = new CustomEventQueue();

    @Override
    void beforeShowingWindow() {
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(newEventQueue);
    }

    @After
    public void cleanup() {
        newEventQueue.remove();
    }

    @Test
    public void type_keys_before_timeout() {
        giveFocusToTextField();
        final KeyRecorder recorder = KeyRecorder.attachTo(window.textField);
        Executors.newSingleThreadExecutor().execute(new Runnable() {
            public void run() {
                robot.pressAndReleaseKeys(VK_A, VK_B, VK_C);
            }
        });
        pause(new Condition("until all keys are typed") {
            @Override
            public boolean test() {
                Integer[] expectedKeys = array(VK_A, VK_B, VK_C);
                return recorder.keysWerePressed(expectedKeys) && recorder.keysWereReleased(expectedKeys);
            }
        }, timeout(1000));
    }

    private class CustomEventQueue extends EventQueue {
        protected void dispatchEvent(final AWTEvent event) {
            super.dispatchEvent(event);
        }

        public void remove() {
            pop();
        }
    }
}

As discussed at https://groups.google.com/d/msg/easytesting/bAt1nWx55FM/CPbXguc3whQJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant