Page MenuHomePhabricator

Create mocha tests in the tool
Open, Needs TriagePublic

Description

Add mocha tests in the tool's back-end to verify the Mongo DB connection and check the UserModel.

Event Timeline

Change 658551 had a related patch set uploaded (by Gopavasanth; owner: Gopavasanth):
[labs/tools/video-cut-tool-back-end@master] Add mocha tests to verify the Mongo DB connection, UserModel and VideoModel.

https://gerrit.wikimedia.org/r/658551

Its weird tests are passing fine locally but not with Jenkins, Any clue?

Screenshot from 2021-01-27 11-33-29.png (379×727 px, 37 KB)

hashar subscribed.

On the change https://gerrit.wikimedia.org/r/c/labs/tools/video-cut-tool-back-end/+/658551/ , CI reports the failure with:

Main test build failed.

Clicking on that links brings you to the build output which shows:

MongoNetworkError: failed to connect to server [localhost:27017]
+ npm ci
added 384 packages in 4.881s
+ npm run-script test

> video-cut-tool-back-end@0.0.1 test /src
> mocha



  DB Saving records
DB Connection error { MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/src/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:189:13)
    at connect (/src/node_modules/mongodb-core/lib/connection/pool.js:557:14)
    at makeConnection (/src/node_modules/mongodb-core/lib/connection/connect.js:39:11)
    at callback (/src/node_modules/mongodb-core/lib/connection/connect.js:261:5)
    at Socket.err (/src/node_modules/mongodb-core/lib/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:277:13)
    at Socket.emit (events.js:189:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }
    1) Saves user records to the database
    2) Saves video records to the database


  0 passing (4s)
  2 failing

  1) DB Saving records
       Saves user records to the database:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/src/test/saving.js)
  

  2) DB Saving records
       Saves video records to the database:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/src/test/saving.js)
  


The Docker image providing NodeJS / npm is docker-registry.wikimedia.org/releng/node10-test-browser, it is based on a Debian distribution.

MongoDB license has been changed to the non-free license SSPL, it has thus been removed from Debian ( https://bugs.debian.org/915537 ) and we thus can not install it since we do not have any package available (plus it is not free software).

There a few way you can address the issue:

A) Drop support for MongoDB / switch to a different object storage backend. Assuming the software is running on WMCS / https://wikitech.wikimedia.org/wiki/Portal:Toolforge Toolforge, you will surely have to drop MongoDB eventually.

B) Split the MongoDB tests to a different test suite which will not be invoked when running npm run-script test. For example add a test-mongodb script which would invoke mocha spec/mongodb while tests not relaying on mongodb would be invoked by npm run-script test and be placed in a different directory such as spec/unit.

npm run-script test-mongodbmocha tests/mongodb
npm run-script testmocha tests/unit

This way CI would not run mongodb based tests, it is up to developers to run them locally assuming they have MongoDB running.

C) Have the test suite to mock any calls trying to reach MongoDB and instead provide a fixtures that mimic the replies MongoDB would have done. This way you are no more dependent from MongoDB.

@Gopavasanth hi, can i work on this? if yes do guide me a bit about what to do in little brief.

Hi Naman, Thanks for your interest on this ticket, let's wait until T290241: Refactor main code get merged into our codebase and you can start working on this :)

Change 658551 abandoned by Gopavasanth:

[labs/tools/video-cut-tool-back-end@master] Add mocha tests to verify the Mongo DB connection, UserModel and VideoModel.

Reason:

No more needed.

https://gerrit.wikimedia.org/r/658551

Hey @Gopavasanth I have written a mocha test to test the mongoDB connection.

Screenshot from 2023-02-14 21-03-27.png (545×1 px, 95 KB)

it passes the test should I create a patch for it ?

Hey @Gopavasanth I have written a mocha test to test the mongoDB connection.

Screenshot from 2023-02-14 21-03-27.png (545×1 px, 95 KB)

it passes the test should I create a patch for it ?

Imo we should not be using Mocha, since we plan to use to Jest for the frontend we should also use jest for the backend. It doesn't make sense to have two types of testing systems on the same project :(