Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace mocha and blanket with ava and nyc #506

Closed
wants to merge 69 commits into from
Closed

Conversation

OmgImAlexis
Copy link
Member

This is a WIP so please keep that in mind if you decide to review before I'm 100% finished.

Since there's no easy way to check the tests are evaluating the same before and after I'd highly suggest we get at least 2 people to review this.

package.json Outdated
"date.js": "~0.3.1",
"debug": "^2.6.8",
"debug": "~3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of these changes by rebasing with master git rebase origin/master

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a problem since we squash the commits, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup no problemo!

@OmgImAlexis
Copy link
Member Author

OmgImAlexis commented Aug 19, 2017

Can someone explain this test to me? Converted it to ava and now it fails and I think it's because ava is running faster than mocha but I'm not 100% sure.

it('does not process locked jobs', done => {
  const history = [];

  jobs.define('lock job', {
    lockLifetime: 300
  }, (job, cb) => {
    history.push(job.attrs.data.i);

    setTimeout(() => {
      cb();
    }, 150);
  });

  jobs.start();

  jobs.now('lock job', {i: 1});
  jobs.now('lock job', {i: 2});
  jobs.now('lock job', {i: 3});

  setTimeout(() => {
    expect(history).to.have.length(3);
    expect(history).to.contain(1);
    expect(history).to.contain(2);
    expect(history).to.contain(3);
    done();
  }, 500);
});

@agenda agenda deleted a comment from coveralls Aug 19, 2017
@OmgImAlexis
Copy link
Member Author

@simison

@simison
Copy link
Member

simison commented Aug 19, 2017

Sorry but I don't really have insight into that test :-/ Maybe @lushc can figure out what's going on in here?

In case pinging also @rschmukler

@OmgImAlexis
Copy link
Member Author

If I can get help with a few of the integration tests then this should be done by the end of next week.

@OmgImAlexis
Copy link
Member Author

I've got 113/123 tests passing so I've only got 10 left to finish off and I think we should be good to then review and merge.

➜  agenda git:(add-ava) ava --verbose --serial                     

  ✔ agenda › returns itself
  ✔ agenda › sets a default processEvery
  ✔ agenda › cancel › returns nothing
  ✔ agenda › cancel › should cancel a job
  ✔ agenda › cancel › should cancel multiple agenda (188ms)
  ✔ agenda › cancel › should cancel agenda only if the data matches
  ✔ agenda › create › returns a job
  ✔ agenda › create › creates a job
  ✔ agenda › default-concurrency › returns itself
  ✔ agenda › default-concurrency › sets the defaultConcurrency
  ✔ agenda › default-lock-lifetime › returns itself
  ✔ agenda › default-lock-lifetime › sets the default lock lifetime
  ✔ agenda › default-lock-lifetime › is inherited by agenda
  ✔ agenda › default-lock-limit › returns itself
  ✔ agenda › default-lock-limit › sets the defaultLockLimit
  ✔ agenda › define › returns a job
  ✔ agenda › define › stores the definition for the job
  ✔ agenda › define › sets the default concurrency for the job
  ✔ agenda › define › sets the default lockLimit for the job
  ✔ agenda › define › sets the default priority for the job
  ✔ agenda › define › takes concurrency option for the job
  ✔ agenda › every › returns a job
  ✔ agenda › every › returns an array of jobs
  ✔ agenda › every › sets the repeatEvery
  ✔ agenda › every › sets the agenda
  ✔ agenda › every › should update a job that was previously scheduled with `every`
  ✔ agenda › jobs › returns jobs
  ✔ agenda › lock-limit › returns itself
  ✔ agenda › lock-limit › sets the lockLimit
  ✔ agenda › max-concurrency › returns itself
  ✔ agenda › max-concurrency › sets the maxConcurrency
  ✔ agenda › mongo › returns itself
  ✔ agenda › mongo › sets the _db directly (779ms)
  ✔ agenda › mongo › sets the _db directly when passed as an option
  ✔ agenda › name › returns itself
  ✔ agenda › name › sets the agenda name
  ✔ agenda › now › returns a job
  ✔ agenda › now › sets the schedule
  ✔ agenda › now › runs the job immediately
  ✔ agenda › process-every › returns itself
  ✔ agenda › process-every › sets the processEvery time
  ✔ agenda › purge › returns nothing
  ✔ agenda › purge › removes all agenda without definitions
  ✔ agenda › save-job › returns a job
  ✔ agenda › save-job › persists job to the database
  ✔ agenda › schedule › returns a job
  ✔ agenda › schedule › returns an array of jobs
  ✔ agenda › schedule › sets the schedule
  ✔ agenda › sort › returns itself
  ✔ agenda › sort › sets the default sort option
  ✔ agenda › unique › returns nothing
  ✔ agenda › unique › should modify one job when unique matches
  ✔ agenda › unique › should not modify job when unique matches and insertOnly is set to true
  ✔ agenda › unique › should create two agenda when unique doesn't match
  - intergration › job-lock › runs a recurring job after a lock has expired
  - intergration › job-lock › runs a one-time job after test.skips lock expires
  - intergration › job-lock › does not process locked jobs
  - intergration › job-lock › does not on-the-fly lock more than agenda._lockLimit jobs
  - intergration › job-lock › does not on-the-fly lock more than definition.lockLimit jobs
  - intergration › job-lock › does not lock more than agenda._lockLimit jobs during processing interval
  - intergration › job-lock › does not lock more than definition.lockLimit jobs during processing interval
  ✔ job › returns itself
  ✔ job › should retry a job (554ms)
  ✔ job › compute-next-time-at › returns the job
  ✔ job › compute-next-time-at › sets to undefined if no repeat at
  ✔ job › compute-next-time-at › it understands repeatAt times
  ✔ job › compute-next-time-at › sets to undefined if no repeat interval
  ✔ job › compute-next-time-at › it understands human intervals
  ✔ job › compute-next-time-at › understands cron intervals
  ✔ job › compute-next-time-at › understands cron intervals with a timezone
  ✔ job › compute-next-time-at › understands cron intervals with a timezone when last run is the same as the interval
  ✔ job › compute-next-time-at › sets nextRunAt to undefined when repeat at time is invalid
  ✔ job › compute-next-time-at › fails the job when repeat at time is invalid
  ✔ job › compute-next-time-at › sets nextRunAt to undefined when repeat interval is invalid
  ✔ job › compute-next-time-at › fails the job when repeat interval is invalid
  ✔ job › disable › returns the job
  ✔ job › disable › sets disabled to true on the job
  ✔ job › enable › returns the job
  ✔ job › enable › sets disabled to false on the job
  ✔ job › events › emits start event
  ✔ job › events › emits start:job name event
  ✔ job › events › emits complete event
  ✔ job › events › emits complete:job name event
  ✔ job › events › emits success event
  ✔ job › events › emits success:job name event
  ✔ job › events › emits fail event
  ✔ job › events › emits fail:job name event
  ✔ job › fail › returns the job
  ✔ job › fail › takes a string
  ✔ job › fail › takes an error object
  ✔ job › fail › sets the failedAt time
  ✔ job › fail › sets the failedAt time equal to lastFinishedAt time
  ✔ job › priority › returns the job
  ✔ job › priority › sets the priority to a number
  ✔ job › priority › parses written priorities
  ✔ job › remove › returns nothing
  ✔ job › remove › removes the job
  ✔ job › repeat-at › returns the job
  ✔ job › repeat-at › sets the repeat at
  ✔ job › repeat-every › returns the job
  ✔ job › repeat-every › sets the repeat interval
  ✔ job › run › returns nothing
  ✔ job › run › updates lastRunAt
  ✔ job › run › updates nextRunAt
  ✔ job › run › fails if job is undefined
  ✔ job › run › handles errors
  ✔ job › run › handles errors with q promises (123ms)
  ✔ job › run › doesn't allow a stale job to be saved
  ✔ job › save › returns the job
  ✔ job › save › calls saveJob on the agenda
  ✔ job › save › doesnt save the job if its been removed
  ✔ job › schedule › returns the job
  ✔ job › schedule › sets the next run time
  ✔ job › schedule › sets the next run time Date object
  ✔ job › start › returns the job
  ✔ job › start › starts/stops the job queue (545ms)
  - job › start › does not run disabled jobs
  - job › start › does not throw an error trying to process undefined jobs
  - job › start › clears locks on stop
  ✔ job › touch › returns nothing
  ✔ job › touch › extends the lock lifetime
  ✔ job › unique › returns the job
  ✔ job › unique › sets the unique property

  113 tests passed [15:15:12]
  10 tests skipped

package.json Outdated
"moment-timezone": "^0.5.0",
"mongodb": "^2.2.10"
"moment-timezone": "~0.5.0",
"mongodb": "~2.2.10"
},
"devDependencies": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With NPM 5.2.0 this was complaining about missing packages when running npm test, so I had to:

npm i eslint-plugin-ava eslint-config-xo eslint-plugin-unicorn eslint-plugin-import --save-dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I wrote that review comment a month ago but forgot to submit it back then. :-) Not sure if that's relevant anymore.

test('returns nothing', t => {
const {agenda} = t.context;

t.is(agenda.cancel('jobA'), undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!

I feel that attempting to cancel a job that didn't exist kinda successfully fulfils the intention here, so it would not need to error? These are always tricky ones.

I remember seeing quite a few issues around cancelling jobs.

package.json Outdated
"moment-timezone": "^0.5.0",
"mongodb": "^2.2.10"
"moment-timezone": "~0.5.0",
"mongodb": "~2.2.10"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to rebase with origin/master as these are updated there.

const clearJobs = agenda => {
return new Promise(resolve => {
debug('jobs cleared');
agenda._mdb.collection('agendaJobs').remove({}, resolve);
Copy link
Member

@simison simison Oct 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also clean up indices here?

Doesn't really matter for Travis but for local testing it might matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We delete the whole database afterwards I was expecting that to trigger MongoDB's auto garbage collection for the indexes. Do we need to clean them ourselves?

Copy link
Member

@simison simison Oct 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection.remove() leaves them there, Collection.drop() is what you'll need.

Although I'm not sure how Mongo garbage collection works exactly, that might handle them as well.

@simison
Copy link
Member

simison commented Jun 11, 2018

Related: #542

@simison simison requested a review from wingsbob June 11, 2018 10:34
@simison simison added this to the 3.0.0 milestone Jun 11, 2018
@OmgImAlexis OmgImAlexis removed this from the 3.0.0 - old milestone Jul 20, 2018
@koresar koresar deleted the add-ava branch August 6, 2021 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants