MockRestServiceServer simulate backend timeout in integration test

前端 未结 5 1910
太阳男子
太阳男子 2021-02-12 20:02

I am writing some kind of integration test on my REST controller using MockRestServiceServer to mock backend behaviour. What I am trying to achieve now is to simulate very slow

5条回答
  •  佛祖请我去吃肉
    2021-02-12 20:56

    In general, you can define your custom request handler, and do a nasty Thread.sleep() there.

    This would be possible in Restito with something like this.

    Action waitSomeTime = Action.custom(input -> {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return input;
    });
    
    whenHttp(server).match(get("/asd"))
            .then(waitSomeTime, ok(), stringContent("Hello World"))
    

    Not sure about Spring, however. You can easily try. Check DefaultResponseCreator for inspiration.

提交回复
热议问题