Page MenuHomeSoftware Heritage

WIP - Unit tests for the mongo backend
AbandonedPublic

Authored by jayeshv on Sep 17 2021, 3:52 PM.

Details

Reviewers
aeviso
vlorentz
Group Reviewers
Reviewers
Summary

Work in progress- Not ready for review yet

Unit tests for the mongo backend
Using a mock mongo database for tests.
These are not to replace existing functional and integration tests.
These are to test the methods in isolation. This will be useful
in storage backend refactoring.
This is not backend agnostic at the moment but can later be re-factored.

Diff Detail

Repository
rDPROV Provenance database
Branch
arcpatch-D6291
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 23817
Build 37138: Phabricator diff pipeline on jenkinsJenkins console · Jenkins
Build 37137: arc lint + arc unit

Event Timeline

Build is green

Patch application report for D6291 (id=22866)

Rebasing onto d0a11a1499...

Current branch diff-target is up to date.
Changes applied before test
commit bc118d601733f3ba444767668d05dbd603ecd07e
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 15:47:16 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/353/ for more details.

jayeshv edited the summary of this revision. (Show Details)

Added missing tests for multiple records

Build is green

Patch application report for D6291 (id=22878)

Rebasing onto d0a11a1499...

Current branch diff-target is up to date.
Changes applied before test
commit 8b59db33b2fc0c476aab367239a83c764169a3de
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 16:53:50 2021 +0200

    Added tests for multiple records

commit bc118d601733f3ba444767668d05dbd603ecd07e
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 15:47:16 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/354/ for more details.

Build is green

Patch application report for D6291 (id=22889)

Rebasing onto d0a11a1499...

Current branch diff-target is up to date.
Changes applied before test
commit 733421024d0415cf0df4861e3cb48e7c99f39c7d
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Mon Sep 20 08:16:46 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/355/ for more details.

aeviso requested changes to this revision.Sep 20 2021, 10:31 AM
aeviso added a subscriber: aeviso.

I'm not really convinced about adding this test, it essentially recreates situations that are already tested in the test_provenance_storage test (but there it is done for all backends at once).
Also, performing direct queries to the mongodb object breaks the abstraction layer which means any future refactoring will require reimplementing this tests.
I rather design test to be independent of the actual implementation, so that they check that the class behave as expected from a semantic point of view.

swh/provenance/tests/mongo/test_backend.py
20

Please add full type annotations (return type and parameters in all methods)

This revision now requires changes to proceed.Sep 20 2021, 10:31 AM

I'm not really convinced about adding this test, it essentially recreates situations that are already tested in the test_provenance_storage test (but there it is done for all backends at once).
Also, performing direct queries to the mongodb object breaks the abstraction layer which means any future refactoring will require reimplementing this tests.
I rather design test to be independent of the actual implementation, so that they check that the class behave as expected from a semantic point of view.

It is good idea to have unit tests as independent as possible. We have to have different tests to make sure all the interfaces behave the same. (I believe that should be part of an integration test suite)

Same set of tests for different implementations will often make tests complex and harder to read.
I think we don't have to worry much about number lines in the test code. The best approach would be to make them fail even in the slightest change.

  • Unit tests for mongo backend
  • Added tests for multiple records
  • Added more unit tests
  • String corrections

Build is green

Patch application report for D6291 (id=22935)

Rebasing onto d0a11a1499...

Current branch diff-target is up to date.
Changes applied before test
commit b2dad8f11b94fd6acef1c51dd176433c17285222
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Sep 21 17:18:32 2021 +0200

    String corrections

commit 20c316e508e4a1119e61d91ee0f99ba999edcc28
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Sep 21 17:08:12 2021 +0200

    Added more unit tests
    
    Added tests for origin_add and directory get
    Added stubs for mongo datamodel tests (indexes and data types)

commit 8b59db33b2fc0c476aab367239a83c764169a3de
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 16:53:50 2021 +0200

    Added tests for multiple records

commit bc118d601733f3ba444767668d05dbd603ecd07e
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 15:47:16 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/358/ for more details.

  • added stubs
  • small fixes
  • more doc strings
  • Better doc strings

Build is green

Patch application report for D6291 (id=22953)

Rebasing onto 4c087ea0ec...

First, rewinding head to replay your work on top of it...
Applying: Unit tests for mongo backend
Applying: Added tests for multiple records
Applying: Added more unit tests
Applying: String corrections
Applying: added stubs
Applying: small fixes
Applying: more doc strings
Applying: Better doc strings
Changes applied before test
commit 8591dcef03ea040702c0d32135e3b3d770794add
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Sep 22 10:29:08 2021 +0200

    Better doc strings

commit 974f3722a84a9d262c5413169a806833d246b373
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Sep 22 10:05:32 2021 +0200

    more doc strings

commit 849e21394c0ed2e242d61581c1b07c91409022e7
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Sep 22 09:45:09 2021 +0200

    small fixes

commit 2c93b63c07621b96c27f640442a202674d62d491
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Sep 21 17:52:45 2021 +0200

    added stubs

commit 99a7e64d588cc2a4baa89893edd412c2a0cd3c4d
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Sep 21 17:18:32 2021 +0200

    String corrections

commit 501d4973f160b627121291ce3289a864106176aa
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Tue Sep 21 17:08:12 2021 +0200

    Added more unit tests
    
    Added tests for origin_add and directory get
    Added stubs for mongo datamodel tests (indexes and data types)

commit 77c3b3c7a44750cebba38805151687018ae55351
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 16:53:50 2021 +0200

    Added tests for multiple records

commit 177224f55570c1567e85b3fe7e8cb8b0ac4a7b54
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Sep 17 15:47:16 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/359/ for more details.

jayeshv retitled this revision from Unit tests for content and directory add methods in mongo to WIP - Unit tests for the mongo backend.Sep 22 2021, 10:36 AM
jayeshv edited the summary of this revision. (Show Details)
jayeshv edited the summary of this revision. (Show Details)

more tests

Build is green

Patch application report for D6291 (id=23011)

Rebasing onto 4c087ea0ec...

First, rewinding head to replay your work on top of it...
Applying: Unit tests for mongo backend
Changes applied before test
commit a3bc0efb1ad30dd3c7391b961c90a28358a686cf
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Thu Sep 23 16:28:37 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

See https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/366/ for more details.

  • Unit tests for mongo backend
  • stubs
  • small change
  • more
  • missing test stubs

Build has FAILED

Patch application report for D6291 (id=23332)

Rebasing onto 04ff73ea98...

First, rewinding head to replay your work on top of it...
Applying: Unit tests for mongo backend
Applying: stubs
Applying: small change
Applying: more
Applying: missing test stubs
Changes applied before test
commit 25f4768e043935ddd6dee9f0f5f896c5c4f74e50
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed Oct 6 11:45:43 2021 +0200

    missing test stubs

commit bef051258cb142cb1dadb9d66f91b9dbd56b9c5b
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Mon Oct 4 12:38:47 2021 +0200

    more

commit e286c1fb040bb65cad594cb9f9bfc9c1f5295c40
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Mon Oct 4 09:34:24 2021 +0200

    small change

commit 30683b5ad6ab6a97821772d512e635911c8a2b37
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Fri Oct 1 15:34:36 2021 +0200

    stubs

commit 27568fefe56dd61069f760942298c50fabb0e2f1
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Thu Sep 23 16:28:37 2021 +0200

    Unit tests for mongo backend
    
    Unit tests for content and direcotory add methods.
    Using a mock mongo database for tests.

Link to build: https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/433/
See console output for more information: https://jenkins.softwareheritage.org/job/DPROV/job/tests-on-diff/433/console