Spring shell blocks tests
Asked Answered
O

3

6

When I added spring shell to project

    <dependency>
        <groupId>org.springframework.shell</groupId>
        <artifactId>spring-shell-starter</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>

tests began to hangs and never ends. After stop I see in logs

2020-02-22 20:00:14.271  INFO 9812 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2020-02-22 20:00:14.933  WARN 9812 --- [           main] org.jline                                : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
2020-02-22 20:00:15.229  INFO 9812 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [192.168.1.10:5672]
2020-02-22 20:00:15.312  INFO 9812 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Created new connection: rabbitConnectionFactory#4c32d208:0/SimpleConnection@608c36a6 [delegate=amqp://[email protected]:5672/, localPort= 65404]
2020-02-22 20:00:15.401  INFO 9812 --- [           main] c.umbrella.app.BackendApplicationTests   : Started BackendApplicationTests in 12.969 seconds (JVM running for 14.251)

Process finished with exit code -1
shell:>

The problem reproduces when I run tests from IDE and mvn. How to avoid problem with tests?

Oosphere answered 22/2, 2020 at 13:5 Comment(0)
O
4

I found solution, it needs to add next properties to each test:

@SpringBootTest(properties = {
    InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=false",
    ScriptShellApplicationRunner.SPRING_SHELL_SCRIPT_ENABLED + "=false"
})
Oosphere answered 23/2, 2020 at 16:23 Comment(0)
C
9

In Spring Shell 2:

@SpringBootTest(properties = "spring.shell.interactive.enabled=false")
Chui answered 5/7, 2022 at 6:39 Comment(0)
O
4

I found solution, it needs to add next properties to each test:

@SpringBootTest(properties = {
    InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=false",
    ScriptShellApplicationRunner.SPRING_SHELL_SCRIPT_ENABLED + "=false"
})
Oosphere answered 23/2, 2020 at 16:23 Comment(0)
K
0

In case of updating @SpringBootTest you have to do that for each test class. I think the better approach is to move shell enabling to exact profile where you need that. This is how it may look yours application.yaml:

---
spring:
  config:
    activate:
      on-profile: dev
  shell:
    script:
      enabled: true
    interactive:
      enabled: true

Thanks to that each running test by default has not enabled shell.

Kramer answered 11/8, 2024 at 6:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.