Fray:一个针对 JVM 的受控并发测试框架
Fray: A Controlled Concurrency Testing Framework for the JVM

原始链接: https://github.com/cmu-pasta/fray

Fray是一个Java并发测试工具,旨在发现和调试多线程代码中的竞争条件、死锁以及其他并发相关问题。它使用概率并发测试和偏序采样等技术来探索各种线程交错。Fray提供确定性重放功能,以便轻松调试特定场景。 对于JUnit 5用户,Fray通过`@ConcurrencyTest`注解和`@ExtendWith(FrayTestExtension.class)`无缝集成。它还提供更通用的`FrayInTestLauncher`,可用于其他测试框架。 与构建系统的集成很简单。Gradle用户可以在其构建文件中添加特定插件。Maven用户应该添加一个插件和fray-junit依赖项。Fray欢迎贡献,并为开发者提供了相关指南。 Fray得到了美国国家科学基金会和亚马逊研究奖的支持。

Hacker News 上讨论了卡内基梅隆大学 PASTA 实验室开发的 JVM 并发测试框架 "Fray"。该工具旨在帮助开发者发现 Java 代码中的并发问题。 一位评论者 (AugustoCAS) 质疑 Fray 如何更好地处理与 JUnit 的并行测试执行,以及它是否支持纤程 (fibers),并指出 Fray 似乎挂钩到线程启动。另一位评论者 (gavinray) 指出了 JetBrains 的 "lincheck" 作为替代方案,这是一个用于自动推导出并发数据结构和原语的线性化证明的工具。Lincheck 提供了一种形式化验证方法,用于确保并发数据结构的行为正确。
相关文章

原文

Build Gradle Maven JetBrain Plugin Discord

logo

Fray is a concurrency testing tool for Java that can help you find and debug tricky race conditions that manifest as assertion violations, run-time exceptions, or deadlocks. It performs controlled concurrency testing using state-of-the-art techniques such as probabilistic concurrency testing or partial order sampling. Fray also provides deterministic replay capabilities for debugging specific thread interleavings. Fray is designed to be easy to use and can be integrated into existing testing frameworks.

If you are using JUnit 5, you can use the @ConcurrencyTest annotation to mark a test as a concurrency test. You also need to add the @ExtendWith(FrayTestExtension.class) annotation to the test class.

import org.pastalab.fray.junit.junit5.FrayTestExtension;
import org.pastalab.fray.junit.junit5.annotations.ConcurrencyTest;

@ExtendWith(FrayTestExtension.class)
public class SimpleTest {
    @ConcurrencyTest
    public void concurrencyTest() {
        ... // some multithreaded code
        assert(...);
    }
}

Fray can be used with other testing frameworks as well. You may use the FrayInTestLauncher

import org.pastalab.fray.junit.plain.FrayInTestLauncher;

public void test() {
    FrayInTestLauncher.INSTANCE.launchFrayTest(() -> {
        ... // some multithreaded code
        assert(...);
    });
}

To use Fray with Gradle, add the following plugin to your build.gradle file:

plugins {
    id("org.pastalab.fray.gradle") version "0.5.1"
}
  • First please add Fray plugin to your project
<plugin>
    <groupId>org.pastalab.fray.maven</groupId>
    <artifactId>fray-plugins-maven</artifactId>
    <version>0.5.1</version>
    <executions>
        <execution>
            <id>prepare-fray</id>
            <goals>
                <goal>prepare-fray</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • Next, please add the fray-junit dependency
<dependency>
    <groupId>org.pastalab.fray</groupId>
    <artifactId>fray-junit</artifactId>
    <version>0.5.1</version>
    <scope>test</scope>
</dependency>

Contributions to Fray are both welcomed and appreciated! Please see our contributing guide for more information on how to contribute to Fray.

This material is based upon work supported by the National Science Foundation under Grant No. 2120955. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

The Fray project was also supported by an Amazon Research Award.

联系我们 contact @ memedata.com