Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #7223

Closed
Open
Created Jun 27, 2014 by Administrator@rootOwner

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.

Assignee
Assign to
Time tracking