Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the task in 'stop' method of GlobalExtension does not complete when the jvm shutdown. #977

Open
WenRui13 opened this Issue Mar 3, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@WenRui13
Copy link

WenRui13 commented Mar 3, 2019

Issue description

I custom GlobalExtension to collect my test reslut and push to our report platform, but the 'stop' method in my extension does not work correctly, the task in it does not run completely then the JVM shutdown and spockframework stoped.

How to reproduce

    @Override
    public void stop() {
        //上报天书
//        ExecutorService exec = Executors.newFixedThreadPool(1);
//        Future<String> future = exec.submit(() -> testResultCollector.push2platfrom());
//        try {
//            String result = future.get(10, TimeUnit.MINUTES);
//            System.out.println(result);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        } catch (TimeoutException e) {
//            e.printStackTrace();
//        } finally {
//            exec.shutdown();
//        }


//        Runtime.getRuntime().addShutdownHook(new Thread(() -> testResultCollector.push2platfrom()));


        testResultCollector.push2platfrom();
    }

Additional Environment information

Version of your build tool(if used), Java, Groovy, IDE, OS etc

Java/JDK

jdk1.8

versions

 <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.10</version>
        </dependency>

        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>1.1-groovy-2.4</version>
            <!--<scope>test</scope>-->
        </dependency>


        <dependency>
            <groupId>com.athaydes</groupId>
            <artifactId>spock-reports</artifactId>
            <version>1.6.1</version>
        </dependency>

@rtretyak

This comment has been minimized.

Copy link

rtretyak commented Mar 3, 2019

This looks related to my problem in #966

@WenRui13

This comment has been minimized.

Copy link
Author

WenRui13 commented Mar 3, 2019

@rtretyak dig into the source code to see what happened. I think that may be relate to thread. how complicated it is.

@WenRui13

This comment has been minimized.

Copy link
Author

WenRui13 commented Mar 3, 2019

@rtretyak problem may occur in this code,the 'stop' method's invoke chain is bellow:
image

@leonard84

This comment has been minimized.

Copy link
Member

leonard84 commented Mar 4, 2019

Yeah in 1.x this method is best effort and may not be called at all or the jvm may terminate before completion if you try to do some long running stuff. The reason is that the JUnit 4 Framework does not offer a hook for Spock, so we are using a ShutdownHook as a workaround, with all its limitations.

@WenRui13

This comment has been minimized.

Copy link
Author

WenRui13 commented Mar 21, 2019

@leonard84 how to solve this problem ? tks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.