Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

1.8 KB
Raw Blame
package opensuite.core;

import opensuite.testkit.Expect;
import opensuite.testkit.Harness;

import java.util.LinkedHashMap;
import java.util.Map;

public class FreezeWatchTest {
    public void run() {
        Harness.suite("FreezeWatch");

        Harness.test("a window thread long overdue is stuck; one on time is not", () -> {
            long now = 100_000;
            Expect.isTrue(FreezeWatch.stuck(now, now - FreezeWatch.STUCK_MS, now - FreezeWatch.CHECK_MS), "overdue is stuck");
            Expect.isTrue(!FreezeWatch.stuck(now, now - 1500, now - FreezeWatch.CHECK_MS), "on time is not stuck");
        });

        Harness.test("a watcher that was itself held up proves nothing", () -> {
            long now = 100_000;
            Expect.isTrue(!FreezeWatch.stuck(now, now - 60_000, now - 60_000), "after a sleep nothing is reported");
        });

        Harness.test("the report puts the window's thread first and says where each thread is", () -> {
            Map<Thread, StackTraceElement[]> threads = new LinkedHashMap<>();
            Thread worker = new Thread(() -> { }, "a-worker");
            Thread window = new Thread(() -> { }, "AWT-EventQueue-0");
            threads.put(worker, new StackTraceElement[] {new StackTraceElement("opensuite.x.Worker", "wait", "Worker.java", 12)});
            threads.put(window, new StackTraceElement[] {new StackTraceElement("opensuite.x.Panel", "build", "Panel.java", 34)});
            String r = FreezeWatch.report(threads, 7000);
            Expect.isTrue(r.contains("for 7 seconds"), "says how long");
            Expect.isTrue(r.indexOf("AWT-EventQueue-0") < r.indexOf("a-worker"), "window thread first");
            Expect.isTrue(r.contains("at opensuite.x.Panel.build(Panel.java:34)"), "says where it is");
        });
    }
}