All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hgc.jarspec.mixins.AsynchronousBehaviour Maven / Gradle / Ivy

package io.hgc.jarspec.mixins;

import io.hgc.jarspec.Test;

public interface AsynchronousBehaviour {
    int INITIAL_BACKOFF = 20;

    default void waitFor(Test test) throws Exception {
        long startTime = System.currentTimeMillis();
        int timeout = getTimeoutMillis();
        int backoff = INITIAL_BACKOFF;
        while (true) {
            try {
                test.run();
                return;
            } catch (AssertionError e) {
                if (System.currentTimeMillis() > startTime + timeout) {
                    throw new AssertionError("Assertion failed after " + timeout + "ms", e);
                }
                Thread.sleep(backoff += backoff >> 3);
            }
        }
    }

    default int getTimeoutMillis() {
        return 5000;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy