Skip to content

Commit

Permalink
trigger cargo build from maven for better parallel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tillerino committed May 31, 2024
1 parent 2d38053 commit 69beba0
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 84 deletions.
25 changes: 2 additions & 23 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,13 @@
help:
@just --list

# Build a specific Rust module for x86_64-unknown-linux-musl and copy the result to the main folder.
# Go `rustup target add x86_64-unknown-linux-musl` to install the target if not present.
build-rust-for-docker module:
cargo build --target=x86_64-unknown-linux-musl --release --manifest-path tillerinobot-{{module}}/Cargo.toml
cp tillerinobot-{{module}}/target/x86_64-unknown-linux-musl/release/main tillerinobot-{{module}}/target/release/main

# Build all Rust modules for x86_64-unknown-linux-musl and copy the result to the main folder
build-rust-for-docker-all:
just build-rust-for-docker live
just build-rust-for-docker irc

# Build all Rust modules for x86_64-unknown-linux-musl and copy the result to the main folder
build-rust-for-docker-fast:
just build-rust-for-docker live &
just build-rust-for-docker irc
wait

# Clean and verify while building the Rust modules explicitly
clean-verify:
mvn clean
just build-rust-for-docker-all
mvn verify
mvn clean verify -P rust

# Do more stupid things, faster :sunglasses:
clean-verify-fast:
mvn clean
just build-rust-for-docker-fast
mvn verify -T 2
mvn clean verify -T 3 -P rust

# Install the JARs into the Maven repository without testing anything.
install:
Expand Down
42 changes: 42 additions & 0 deletions tillerinobot-irc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,46 @@
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>rust</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>build-rust</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cargo</executable>
<arguments>
<argument>build</argument>
<!-- to install this target: rustup target add x86_64-unknown-linux-musl -->
<argument>--target=x86_64-unknown-linux-musl</argument>
<argument>--release</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/target/x86_64-unknown-linux-musl/release</directory>
<targetPath>${project.basedir}/target/release</targetPath>
<includes>
<include>main</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
</project>
4 changes: 2 additions & 2 deletions tillerinobot-irc/src/main/rust/rabbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Default for RabbitConfig {
host: var("RABBIT_HOST").unwrap_or_else(|_| "rabbitmq".into()),
port: var("RABBIT_PORT").ok().map(|s| str::parse(s.as_str()).expect("unable to parse RABBIT_PORT")).unwrap_or(5672),
vhost: var("RABBIT_VHOST").unwrap_or_else(|_| "/".into()),
}
}
}
}

Expand Down Expand Up @@ -245,4 +245,4 @@ pub(crate) mod game_chat_client {
pub fn now_millis() -> i64 {
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis() as i64
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.engio.mbassy.listener.Handler;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
Expand Down Expand Up @@ -119,6 +120,8 @@ void withEvents(Consumer<List<ClientEvent>> consumer) {
}

@Test
// This test kills the shared rabbit MQ container, which messes with parallel tests.
@Ignore
public void livenessReactsToRabbit() throws Exception {
RabbitMqContainer.stop();
await().untilAsserted(() -> RestAssured.when().get("/live").then().statusCode(503));
Expand Down
2 changes: 0 additions & 2 deletions tillerinobot-irc/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
</Root>
<!-- from main -->
<Logger name="io.undertow.request.error-response" level="info"/>

<Logger name="org.pircbotx" level="error"/>
<Logger name="org.eclipse.jetty" level="info"/>
<Logger name="org.springframework" level="warn"/>
<Logger name="org.jboss.logging" level="info"/>
Expand Down
42 changes: 42 additions & 0 deletions tillerinobot-live/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,46 @@
<classifier>tests</classifier>
</dependency>
</dependencies>

<profiles>
<profile>
<id>rust</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>build-rust</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cargo</executable>
<arguments>
<argument>build</argument>
<!-- to install this target: rustup target add x86_64-unknown-linux-musl -->
<argument>--target=x86_64-unknown-linux-musl</argument>
<argument>--release</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/target/x86_64-unknown-linux-musl/release</directory>
<targetPath>${project.basedir}/target/release</targetPath>
<includes>
<include>main</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
</project>
7 changes: 5 additions & 2 deletions tillerinobot-live/src/main/rust/rabbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ pub(crate) async fn run_rabbit() {
loop {
match consume_rabbit().await {
Ok(_) => println!("rabbit body succeeded. what the hell?"),
Err(e) => println!("Rabbit error: {}", e)
Err(e) => {
println!("Rabbit error: {}", e);
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}
}
}
}
Expand Down Expand Up @@ -166,4 +169,4 @@ fn anonymize_user_id(conn: &Conn, name: &String) -> i32 {
let mut truncated: [u8; 4] = [ 0, 0, 0, 0 ];
truncated.clone_from_slice(&digest.finalize()[0..4]);
i32::from_le_bytes(truncated)
}
}
30 changes: 30 additions & 0 deletions tillerinobot-live/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
<!-- from main -->
<Logger name="io.undertow.request.error-response" level="info"/>

<Logger name="org.eclipse.jetty" level="info"/>
<Logger name="org.springframework" level="warn"/>
<Logger name="org.jboss.logging" level="info"/>
<Logger name="com.github.dockerjava" level="info"/>
<Logger name="com.networknt" level="info"/>
<Logger name="org.testcontainers" level="info"/>
<Logger name="jndi" level="info"/>
<Logger name="org.apache.http" level="info"/>
<Logger name="io.netty" level="info"/>
<Logger name="tc" level="info"/>
<Logger name="tc.localhost" level="debug"/>

<Logger name="org.tillerino.irc" level="info"/>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@

import javax.annotation.CheckForNull;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.Value;

/**
* Response sent to the user as the result of a command
Expand All @@ -29,57 +22,45 @@ public interface GameChatResponse {
* A regular IRC message. This should not be used as the direct response to
* a command, but for other auxiliary messages, see {@link Success}.
*/
@Value
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor(onConstructor = @__(@JsonCreator))
public static class Message extends GameChatResponse.SingletonResponse {
String content;
public record Message(String content) implements GameChatResponse.SingletonResponse {
}

/**
* A regular IRC message, which will be logged as a successfully executed command.
* This is the message that the command duration will be logged for.
*/
@Value
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor(onConstructor = @__(@JsonCreator))
public static class Success extends GameChatResponse.SingletonResponse {
String content;
public record Success(String content) implements GameChatResponse.SingletonResponse {
}

/**
* An "action" type IRC message
*/
@Value
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor(onConstructor = @__(@JsonCreator))
public static class Action extends GameChatResponse.SingletonResponse {
String content;
public record Action(String content) implements GameChatResponse.SingletonResponse {
}

/**
* Adds another response to the current one.
*/
@SuppressFBWarnings("SA_LOCAL_SELF_COMPARISON")
default GameChatResponse then(@CheckForNull GameChatResponse nextResponse) {
if (nextResponse instanceof NoResponse || nextResponse == null) {
default GameChatResponse then(@CheckForNull GameChatResponse that) {
if (that instanceof NoResponse || that == null) {
return this;
}
if (this instanceof NoResponse) {
return nextResponse;
return that;
}
ResponseList list = new ResponseList();
if (this instanceof ResponseList thisList) {
list.responses.addAll(thisList.responses);
List<GameChatResponse> responses = new ArrayList<>();
if (this instanceof ResponseList(var these)) {
responses.addAll(these);
} else {
list.responses.add(this);
responses.add(this);
}
if (nextResponse instanceof ResponseList nextList) {
list.responses.addAll(nextList.responses);
if (that instanceof ResponseList(var those)) {
responses.addAll(those);
} else {
list.responses.add(nextResponse);
responses.add(that);
}
return list;
return new ResponseList(responses);
}

static NoResponse none() {
Expand Down Expand Up @@ -111,23 +92,17 @@ public Iterable<GameChatResponse> flatten() {
}
}

@EqualsAndHashCode
@ToString
@SuppressFBWarnings(value = "RCN", justification = "Generated code")
@AllArgsConstructor(access = AccessLevel.PACKAGE, onConstructor = @__(@JsonCreator))
public static final class ResponseList implements GameChatResponse {
@Getter
private final List<GameChatResponse> responses = new ArrayList<>();

@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"}, justification = "Record bro")
public record ResponseList(List<GameChatResponse> responses) implements GameChatResponse {
@Override
public Iterable<GameChatResponse> flatten() {
return Collections.unmodifiableList(responses);
}
}

abstract class SingletonResponse implements GameChatResponse {
interface SingletonResponse extends GameChatResponse {
@Override
public Iterable<GameChatResponse> flatten() {
default Iterable<GameChatResponse> flatten() {
return Collections.singletonList(this);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tillerinobot-tests/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
<Logger name="org.pircbotx" level="error"/>

<Logger name="org.eclipse.jetty" level="info"/>
<Logger name="org.springframework" level="warn"/>
<Logger name="org.jboss.logging" level="info"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ public void onResponse(GameChatResponse response, GameChatEvent event) throws In

@SuppressFBWarnings(value = "SA_LOCAL_SELF_COMPARISON", justification = "Looks like a bug")
private Result<Response, Error> handleResponse(GameChatResponse response, GameChatEvent result) throws InterruptedException, IOException {
if (response instanceof Message message) {
return message(message.getContent(), false, result);
} else if (response instanceof Success success) {
return message(success.getContent(), true, result);
} else if (response instanceof Action action) {
String msg = action.getContent();
if (response instanceof Message(String msg)) {
return message(msg, false, result);
} else if (response instanceof Success(String msg)) {
return message(msg, true, result);
} else if (response instanceof Action(String msg)) {
return writer.action(msg, result.getNick()).map(ok -> {
try (MdcAttributes mdc = MdcUtils.with(MdcUtils.MDC_STATE, "sent")) {
if (ok.ping() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private static GameChatResponse messageContaining(String s) {
return new GameChatResponse() {
@Override
public boolean equals(Object arg0) {
return arg0 instanceof Message msg && msg.getContent().contains(s);
return arg0 instanceof Message msg && msg.content().contains(s);
}

@Override
Expand All @@ -431,7 +431,7 @@ private static GameChatResponse successContaining(String s) {
return new GameChatResponse() {
@Override
public boolean equals(Object arg0) {
return arg0 instanceof Success suc && suc.getContent().contains(s);
return arg0 instanceof Success suc && suc.content().contains(s);
}

@Override
Expand Down
Loading

0 comments on commit 69beba0

Please sign in to comment.