dszdiavv474681 2015-12-29 18:34 采纳率: 0%
浏览 122

在测试期间使用golang游乐场功能伪造时间

The golang blog mentions two Go features faketime and timejump: https://blog.golang.org/playground

The part that interests me is:

modify scheduler condition to wait for deadlock, then:
- check if timers are pending
- advance clock to trigger-time of first timer

I would like to know how I can leverage this implementation to run unittests with faketime. By this I mean many unitests that use time.Sleep. Testing in realtime is prohibitive since execution time adds up to hours. In faketime the tests run within split-seconds.

To be clear: I do not plan or want to mess up the runtime. I want to build a fake clock that works.

I am pretty convinced that the above referenced implementation works correctly in the concurrent case. If you have a idea, a tip or two on how to borrow this implementation and build a fake clock from it would be great.

My question is based on the assumption that google won't accept a pull request for runtime/time.go to turn faketime into Faketime or to add "func Faketime(f int64) {faketime = f}".

  • 写回答

1条回答 默认 最新

  • douzhiba6873 2019-09-04 21:05
    关注

    My question is based on the assumption that google won't accept a pull request for runtime/time.go to turn faketime into Faketime or to add "func Faketime(f int64) {faketime = f}".

    4 years later (Sept. 2019), that assumption might be challenged.

    Brad Fitzpatrick just announced:

    So we're moving the #golang playground from Native Client to linux/amd64 binaries with runtime faketime support under gvisor. e.g.

    And (tweet):

    Austin's faketime #golang support is in master (1.14?).
    See golang/go commit 5ff38e4 & its prior two commits.

    Note that the sleep is simulated and instead all writes are prefixed by a binary header containing the fake time, starting from usual Go epoch (play.golang.org).

    See issue 30439 and issue 30324.

    https://pbs.twimg.com/media/EDpDthtU8AAXXd2?format=jpg&name=large

    The context is the playground.
    This is for use by the playground and might not even be documented or supported (kept compatible).
    This is so we can replay sleeps in JavaScript but execute quickly server side.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题