Using StepVerifier in a parallel testing environment - project-reactor

I am having some trouble when using StepVerifier's withVirtualTime and create methods in a parallel testing environment.
private static final Duration DELAY = Duration.ofSeconds(1);
public void testA() {
StepVerifier.withVirtualTime(() -> Mono.just(1).delayElement(DELAY))
.thenAwait(DELAY)
.expectNext(1)
.expectComplete()
.verify();
}
public void testB() {
StepVerifier.create(Mono.just(1).delayElement(DELAY))
.thenAwait(DELAY)
.expectNext(1)
.expectComplete()
.verify();
}
Maven Surefire plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<groups>unit</groups>
<includes>
<include>**/*Test.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>2</threadCount>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
These tests fail with the following exceptions (The full stack traces available on GitHub, please refer links below.):
[ERROR] testA(com.github.hisener.StepVerifierTest) Time elapsed: 0.04 s <<< FAILURE!
java.lang.NullPointerException: timedScheduler
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
[ERROR] testB(com.github.hisener.StepVerifierTest) Time elapsed: 0.043 s <<< FAILURE!
reactor.core.Exceptions$ReactorRejectedExecutionException: Scheduler unavailable
at reactor.core.Exceptions.failWithRejected(Exceptions.java:249)
I don't think it's related to delayElements, for instance, one of the following tests uses timeout and they also fail:
public void testA() {
StepVerifier.withVirtualTime(() -> Mono.just(1)).expectNext(1).expectComplete().verify();
}
public void testB() {
StepVerifier.create(Mono.just(1).timeout(DELAY)).expectNext(1).expectComplete().verify();
}
I have tested on both TestNG and Junit 5, but no luck. The code is available on GitHub:
TestNG https://github.com/hisener/reactor-test-test
JUnit 5 https://github.com/hisener/reactor-test-test/tree/junit5

StepVerifier#withVirtualTime replaces ALL default Schedulers with the virtual time one, so it is not a good idea to use it in parallel

Related

Vaadin: You are asking Spring Security to ignore... This is not recommended?

While starting up my application I see the following warning in my log:
...
2022-09-05 09:14:56,557 WARN [main] org.springframework.security.config.annotation.web.builders.WebSecurity:
You are asking Spring Security to ignore Or [Ant [pattern='/favicon.ico'], Ant [pattern='/manifest.webmanifest'], Ant [pattern='/sw.js'], Ant [pattern='/sw-runtime-resources-precache.js'], Ant [pattern='/offline.html'], Ant [pattern='/offline-stub.html'], Ant [pattern='/icons/icon.png'], Ant [pattern='/themes/**'], Ant [pattern='/icons/icon-144x144.png'], Ant [pattern='/icons/icon-192x192.png'], Ant [pattern='/icons/icon-512x512.png'], Ant [pattern='/icons/icon-16x16.png'], Ant [pattern='/icons/icon-32x32.png'], Ant [pattern='/icons/icon-96x96.png'], Ant [pattern='/icons/icon-180x180.png'], Ant [pattern='/icons/icon-2048x2732.png'], Ant [pattern='/icons/icon-2732x2048.png'], Ant [pattern='/icons/icon-1668x2388.png'], Ant [pattern='/icons/icon-2388x1668.png'], Ant [pattern='/icons/icon-1668x2224.png'], Ant [pattern='/icons/icon-2224x1668.png'], Ant [pattern='/icons/icon-1620x2160.png'], Ant [pattern='/icons/icon-2160x1620.png'], Ant [pattern='/icons/icon-1536x2048.png'], Ant [pattern='/icons/icon-2048x1536.png'], Ant [pattern='/icons/icon-1284x2778.png'], Ant [pattern='/icons/icon-2778x1284.png'], Ant [pattern='/icons/icon-1170x2532.png'], Ant [pattern='/icons/icon-2532x1170.png'], Ant [pattern='/icons/icon-1125x2436.png'], Ant [pattern='/icons/icon-2436x1125.png'], Ant [pattern='/icons/icon-1242x2688.png'], Ant [pattern='/icons/icon-2688x1242.png'], Ant [pattern='/icons/icon-828x1792.png'], Ant [pattern='/icons/icon-1792x828.png'], Ant [pattern='/icons/icon-1242x2208.png'], Ant [pattern='/icons/icon-2208x1242.png'], Ant [pattern='/icons/icon-750x1334.png'], Ant [pattern='/icons/icon-1334x750.png'], Ant [pattern='/icons/icon-640x1136.png'], Ant [pattern='/icons/icon-1136x640.png']].
This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
...
Please advise what do I need to do/add to get rid of that warning.
My SecurityConfiguration looks like so (as copied from an Example-Application):
...package and imports omitted for brevity
#EnableWebSecurity
#Configuration
public class SecurityConfiguration extends VaadinWebSecurityConfigurerAdapter
{
#Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
setLoginView(http, LoginView.class);
}
#Bean
#Override
public UserDetailsService userDetailsService() {
... omitted user details handling for brevity ...
}
}
I am using Vaadin 23.1.2 and Java 17.
You can ignore the warning.
An issue is already reported and this will be fixed soon
https://github.com/vaadin/flow/issues/13868

Seed job fails to create a MavenJob but no error is reported

I created a Junit jenkins test case where a in-memory jenkins instance is launched (as we use #Rule jenkinsrule). The code of the test case is available here.
The test case will create a FreeStyleProject (= seed job) which will use as Groovy script DSL a maven.groovy file
But when the test case is executed, the following message is reported during the the job build execution. The message reports ghe consequence of the import/parsing of the mavenJob.groovy file as the job expects that a new job will be created.
Legacy code started this job. No cause information is available
Running as SYSTEM
Building in workspace /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/workspace/test0
Processing provided DSL script
ERROR: java.io.IOException: Unable to read /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/jobs/mvn-spring-boot-rest-http/config.xml
Finished: FAILURE
And of course no stack trace of the error is stdout or stderr.
How can I investigate the problem and fix it ?
Remark:
If I use the config.xml file and import it in a separate jenkins instance, the job succeeded
config.xml file generated, it looks good (vs same config.xml file created using the UI)
<?xml version='1.1' encoding='UTF-8'?>
<project>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>false</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<javaposse.jobdsl.plugin.ExecuteDslScripts>
<scriptText>mavenJob(&apos;mvn-spring-boot-rest-http&apos;) {
description &apos;A Maven Job compiling the project Spring Boot Rest HTTP Example&apos;
parameters {
gitParameter {
name &apos;SELECTED_TAG&apos;
description &apos;The Git tag to checkout&apos;
type &apos;PT_TAG&apos;
defaultValue &apos;2.3.4-2&apos;
branch &apos;&apos;
branchFilter &apos;origin/(.*)&apos;
quickFilterEnabled false
selectedValue &apos;DEFAULT&apos;
sortMode &apos;DESCENDING_SMART&apos;
tagFilter &apos;*&apos;
useRepository &apos;.*rest-http-example.git&apos;
listSize &apos;10&apos;
}
}
scm {
git {
remote {
url &apos;https://github.com/snowdrop/rest-http-example.git&apos;
// branch(&apos;$SELECTED_TAG&apos;)
branch(&apos;2.3.4-2&apos;)
}
}
}
rootPOM &apos;pom.xml&apos;
goals &apos;clean install&apos;
}</scriptText>
<usingScriptText>true</usingScriptText>
<sandbox>false</sandbox>
<ignoreExisting>false</ignoreExisting>
<ignoreMissingFiles>false</ignoreMissingFiles>
<failOnMissingPlugin>false</failOnMissingPlugin>
<failOnSeedCollision>false</failOnSeedCollision>
<unstableOnDeprecation>false</unstableOnDeprecation>
<removedJobAction>IGNORE</removedJobAction>
<removedViewAction>IGNORE</removedViewAction>
<removedConfigFilesAction>IGNORE</removedConfigFilesAction>
<lookupStrategy>JENKINS_ROOT</lookupStrategy>
</javaposse.jobdsl.plugin.ExecuteDslScripts>
</builders>
<publishers/>
<buildWrappers/>
</project>
Many thanks in advance for your help.
I created a thread discussion here too: https://groups.google.com/g/jenkinsci-users/c/mRSwARFapyA
Charles
The problem was related to many missing dependencies needed to run the test case.
I upgraded the build.gradle file and now that works.
https://github.com/ch007m/jenkins-job-dsl/blob/jenkins-2.271/build.gradle#L53-L72
BTW, the error message reported was not correlated at all to the root cause and How to fix the problem. that should be improved within the code ;-)

Pitest not running with Kotlintest tests

I'm using kotlintest in my projects and I want to run mutation testing with pitest.
Already tried using pitest alone and with junit5 plugin, but the result is always:
Found 0 tests
================================================================================
- Statistics
================================================================================
>> Generated 610 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)
I'm using:
Pitest - 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.4.5'
Pitest junit5 - 'org.pitest:pitest-junit5-plugin:0.9'
Koltintest - 'io.kotlintest:kotlintest-runner-junit5:3.4.2'
I know kotlintest supports pitest since v3.3.0 (according here) but I don't know how to make it work.
Any ideas how to make it run properly?
Thanks!
I was able to crack it
For reference see "PIT test-plugins support" section in gradle pitest plugin documentation
First you need to set up your buildscript like this:
buildscript {
repositories {
mavenCentral()
}
configurations.maybeCreate('pitest')
dependencies {
classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.4.5'
pitest "io.kotlintest:kotlintest-plugins-pitest:3.4.2"
}
}
Then you should set PIT plugin name in pitest block
pitest {
testPlugin = 'KotlinTest'
// rest of your pitest configuration
}
After that it should work. Hope this helps!

Grails refuses to run my integration test

I created a grails integration test using:
$ grails create-integration-test RoundControllerIntegration
and the following code was generated:
package gcbgb
import grails.test.mixin.integration.Integration
import grails.transaction.*
import spock.lang.*
#Integration
#Rollback
class RoundControllerIntegrationSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test something"() {
expect:"fix me"
true == false
}
}
This represents a clearly failing test, but when I run integration tests using:
$ grails test-app -integration
I get no failures...
$ grails test-app -integration
> Configure project :
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
at build_26x4k1g7i20kh9xdxq6diqdhm.run(/home/peter/ownCloud/workspace-halcon/gcbgb/build.gradle:19)
The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
at build_26x4k1g7i20kh9xdxq6diqdhm.run(/home/peter/ownCloud/workspace-halcon/gcbgb/build.gradle:19)
BUILD SUCCESSFUL in 2s
6 actionable tasks: 1 executed, 5 up-to-date
| Tests PASSED

Integration of jbehave with jenkins

I have to integrate jbehave with jenkins. But I don't have idea how to do this. I saw that I have to create a task in Jenkins, but I don't know where I should wire jbehave with this task.
Can somebody help me?
Thanks,
Sarang
So I'm assuming you have JBehave integrated with Maven, correct?
The simple build environment can be set up as follows:
Go to Jenkins and add a new job of type "Build a maven2/3 project"
Configure your project to check out your from whatever source repository you use.
Configure the build phase of the project to run whatever Maven goal you need ("install" will probably work)
Hit save and you have a working project that will execute exactly as it would from a command line.
If you want to see the JBehave test output rendered nicely in Jenkins you should also follow these instructions to configure the Jenkins/XUnit plugin: http://jbehave.org/reference/stable/hudson-plugin.html
You will also need to make sure your project is configured to use the XML Output format in your StoryReporterBuilder to make use of the plugin (not mentioned in the instructions above).
You can visit the following for details:
http://jbehave.org/reference/stable/hudson-plugin.html
Per your comments, you want to specify the stories to run via Jenkins when using the Maven plugin. Here is one way:
Create a subclass of StoryFinder and set it as the storyFinderClass property in your Maven configuration. In the Jenkins commandline launcher, you can pass in stories as a -D system property which can then be read from your StoryFinder.
Commandline
mvn ... -Dcom.sarang.stories="foo.story,bar.story"
Maven
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>[version]</version>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>integration-test</phase>
<configuration>
...
<systemProperties>
<property>
<name>com.sarang.stories</name>
<value>${com.sarang.stories}</value>
</property>
</systemProperties>
<storyFinderClass>com.sarang.MyStoryFinder</storyFinderClass>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
...
</goals>
</execution>
</executions>
</plugin>
StoryFinder
package com.sarang;
import org.jbehave.core.io.StoryFinder;
import java.util.*;
public class MyStoryFinder extends StoryFinder {
#Override
protected List<String> scan(String basedir, List<String> includes,
List<String> excludes) {
//List<String> defaultStories = super.scan(basedir, includes, excludes);
String myStories = System.getProperty("com.sarang.stories");
return Arrays.asList(myStories.split(","));
}
}

Resources