Skip to content
GitLab
项目 群组 主题 代码片段
  • /
  • 帮助
    • 帮助
    • 支持
    • 社区论坛
    • 提交反馈
  • 登录
  • L large
  • 项目信息
    • 项目信息
    • 动态
    • 标记
    • 成员
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者统计
    • 分支图
    • 比较修订版本
  • 议题 21
    • 议题 21
    • 列表
    • 看板
    • 服务台
    • 里程碑
  • 合并请求 12
    • 合并请求 12
  • CI/CD
    • CI/CD
    • 流水线
    • 作业
    • 产物
    • 计划
  • 部署
    • 部署
    • 环境
    • 发布
  • 软件包与镜像库
    • 软件包与镜像库
    • 软件包库
    • 容器镜像库
    • Terraform 模块
    • 模型实验
  • 监控
    • 监控
    • 事件
  • 分析
    • 分析
    • 价值流
    • CI/CD
    • 仓库
  • Wiki
    • Wiki
  • 代码片段
    • 代码片段
  • 动态
  • 分支图
  • 创建新议题
  • 作业
  • 提交
  • 议题看板
收起侧边栏
  • 王权利
  • large
  • 议题
  • #7223

Travis builds fail unnecessarily because of too tight timing constraints in specs.

Created by: jhund

The spec below fails on Travis because it expects two events to happen at the same second. This expectation is valid in a production system, however not on Travis where things can be a lot slower.

Notice that the expected and received value differ by 1 second. This is probably caused by delays in ActiveRecord callbacks running on a slow CI server.

Failures:
  1) Project last_activity methods last_activity_date returns the creation date of the project's last event if present
     Failure/Error: project.last_activity_at.to_i.should == last_event.created_at.to_i
       expected: 1403898527
            got: 1403898526 (using ==)
     # ./spec/models/project_spec.rb:118:in `block (4 levels) in <top (required)>'

To fix it, I propose to make the time comparison less stringent and allow a difference of up to 1 second.

Also I believe that this particular spec has a logic error. It's titled to test project.last_activity_date, however in the test it references project.last_activity_at instead.

The code under test:

def last_activity_date
  last_activity_at || updated_at
end

I'd be happy to submit a pull request that changes

it 'returns the creation date of the project\'s last event if present' do
  last_activity_event = create(:event, project: project)
  project.last_activity_at.to_i.should == last_event.created_at.to_i
end

to

it 'returns the creation date of the project\'s last event if present' do
  last_activity_event = create(:event, project: project)
  (project.last_activity_date - last_event.created_at).to_i.abs.should < 2
end

I checked and didn't find any other instances in model specs were times were cast to integer for comparison.

This bug makes my pull request fail, so I'm highly motivated to fix this. I'm happy to prepare a pull request if this is something you'd like to address.

指派人
分配到
工时统计