How to test DeferredResult timeoutResult

前端 未结 2 1609
醉梦人生
醉梦人生 2020-12-10 12:27

I\'m implementing long polling as per the Spring blog from some time ago.

Here my converted method with same response signature as before, but instead of responding

2条回答
  •  旧时难觅i
    2020-12-10 12:41

    In my case, after going through spring source code and setting the timeout (10000 millisecond) and getting async result solved it for me, as;

     mvcResult.getRequest().getAsyncContext().setTimeout(10000);
     mvcResult.getAsyncResult();
    

    My whole test code was;

    MvcResult mvcResult = this.mockMvc.perform(
                                    post("")
                                    .contentType(MediaType.APPLICATION_JSON)
                                    .content())
                            ***.andExpect(request().asyncStarted())***
                                .andReturn();
    
    ***mvcResult.getRequest().getAsyncContext().setTimeout(10000);***
    ***mvcResult.getAsyncResult();***
    
    this.mockMvc
        .perform(asyncDispatch(mvcResult))
        .andDo(print())
        .andExpect(status().isOk());
    

    Hope it helps..

提交回复
热议问题