首页 > 其他分享 >ZIMP - Unit test timed out because of mock

ZIMP - Unit test timed out because of mock

时间:2023-12-28 20:34:47浏览次数:30  
标签:defer taskdDstributor because ctrl test mock timed store out

 

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestCreateUserAPI$ github.com/ZhangZhihuiAAA/zimplebank/gapi -count=1 -v

=== RUN   TestCreateUserAPI
=== RUN   TestCreateUserAPI/OK
panic: test timed out after 30s

 

            ctrl := gomock.NewController(t)
            defer ctrl.Finish()

            store := mockdb.NewMockStore(ctrl)
            taskdDstributor := mockworker.NewMockTaskDistributor(ctrl)
            tc.buildStubs(store, taskdDstributor)

The controller is locked when checking matching function calls.

To fix this, we need to use two controllers:

            ctrl1 := gomock.NewController(t)
            defer ctrl1.Finish()
            store := mockdb.NewMockStore(ctrl1)

            ctrl2 := gomock.NewController(t)
            defer ctrl2.Finish()
            taskdDstributor := mockworker.NewMockTaskDistributor(ctrl2)
            tc.buildStubs(store, taskdDstributor)

 

标签:defer,taskdDstributor,because,ctrl,test,mock,timed,store,out
From: https://www.cnblogs.com/zhangzhihui/p/17933503.html

相关文章

  • .NET Moq mock internal类型
    .NETFramework以及.NET(Core)5之前的版本在AssemblyInfo.cs文件里添加InternalsVisibleTo声明//ThisassemblyisthedefaultdynamicassemblygeneratedbyCastleDynamicProxy,//usedbyMoq.Ifyourassemblyisstrong-named,pastethefollowinginasingle......
  • 单元测试 - Mockito - 2
    3.Mockito中常用注解3.1可以代替Mock方法的@Mock注解Shorthandformockscreation-@MockannotationImportant!Thisneedstobesomewhereinthebaseclassoratestrunner:快速mock的方法,使用@mock注解。mock注解需要搭配MockitoAnnotations.openMo......
  • Python 如何在测试中使用 Mock
    Mock概念mock的意思是模拟,也就是模拟接口返回的信息,用已有的信息替换它需要返回的信息,从实现对所依赖的模块的测试。一般有两种场景:前端对后端接口的mock,后端服务之间的测试中涉及的mock,常常发生在单元测试的时候。前端mock可以通过一些工具来完成:使用抓包工具Fiddler,Charles来......
  • pytest mock 单测
    mock一般与patch联用 demo.py:defget_sum(x,y):pass--------------------------------------------------------------------importdemofromunittestimportmockdeftest_fun():mock_get_sum=mock.patch('demo.get_sum',return_value=20)......
  • 使用 Helm Chart 部署分布式 GreptimeDB
    部署分布式GreptimeDB文档大纲一、概述什么是HelmChart一、概述什么是HelmChart是一种用于管理和部署Kubernetes应用程序的工具。它通过定义应用程序的资源、依赖关系和配置参数等信息,将应用程序打包成一个可重复部署的单元。HelmChart具有模板化的特性,可以根据不同的环......
  • Docker启动Nacos报错:Nacos Server did not start because dumpservice bean construct
    一、表象重启服务器之后Docker运行Nacos容器,启动成功,但是外网无法访问。查看了一下Nacos启动日志(dockerlogsnacos容器名)二、分析很明显是数据库配``置问题。。如果是数据库配置的问题,可以着重检查以下信息尤其是MySQL内网Host,查询方式见Docker安装Nacos三、解决我已......
  • 单元测试 - Mockito - 1
    1.为什么要使用mockMock可以理解为创建一个虚假的对象,或者说模拟出一个对象,在测试环境中用来替换掉真实的对象,以达到我们可以:验证该对象的某些方法的调用情况,调用了多少次,参数是多少给这个对象的行为做一个定义,来指定返回结果或者指定特定的动作2.Mockito中常用方法2.......
  • 兼容性复制功能/自定义mock数据/通用hook
    *****自定义mockconstresourceList=computed(()=>Array.from({length:20},(_,index)=>index).map((v,i)=>{return{id:i,joinList:Array.from({length:i},(_,index1)=>index1).map((v,......
  • [Clickhouse] Clickhouse 报SQLException : Read timed out
    1问题描述在使用Clickhouse(21.3.4.25)进行大数据量地数据查询,高频报出SQLException:Readtimedout错误2问题分析2.1单次查询:耗时约4s2.2并发20查询:报SQLExceptionReadtimeout,并发5查询:正常2.3整个SQL:查询业务逻辑复杂(多层嵌套、Join、200余行)2.4整个Query......
  • Mock框架moco学习笔记
    目录一、Moco框架基本介绍1.什么是Moco2.Moco原理简介3.Moco的配置和运行4.Moco启动以及第一个demo二、mock的启动及第一个demo1.创建startup.json文件2.启动moco3.浏览器输入本地网址127.0.0.1:8809/demo三、不带参数的get方法:Method(GET)四、带参数的get方法:queries五、不......