Skip to content

[PROPOSAL] Update to unit test structure

Matthew Sevey requested to merge sevey/refactor-renter-tests into master

MERGE REQUEST

MR Guidelines

Overview

This MR came from the desired to be able to easily know how to run all the tests related to a file or subsystem. Golang does allow a way to run all tests in a file but the file needs to be package file_test. The updates in this MR I think have some additional benefits to using the built in pcakage file_test option. Also I believe we had a discussion ~10 months ago about updating out naming convention for tests to make it easier so hopefully people like this 😄

  1. With the naming convention it fits right into how we are currently using our make file so it is easy to remember. i.e. make test-long pkgs=./modules/renter run=TestUploadHeap runs all the tests in uploadheap_test.go.
  2. Having all the tests be subtests allows for an easy highly view at the top of the test file of what tests currently exist.
  3. Having one main test make sure we clean up all the old tests that have no t.Parallel() that could be slowing down the CI.

Example for Visual Changes

$ make test-long pkgs=./modules/renter run=TestUploadHeap
rm -rf cover doc/whitepaper.aux doc/whitepaper.log doc/whitepaper.pdf fullcover release
gofmt -s -l -w ./modules/renter
go vet ./modules/renter
go get golang.org/x/lint/golint
go: found golang.org/x/lint/golint in golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5
golint -min_confidence=1.0 -set_exit_status ./modules/renter
GORACE='history_size=3 halt_on_error=1 atexit_sleep_ms=2000' go test -race --coverprofile='./cover/cover.out' -v -failfast -tags='testing debug netgo' -timeout=3600s ./modules/renter -run=TestUploadHeap -count=1
=== RUN   TestUploadHeap
=== PAUSE TestUploadHeap
=== CONT  TestUploadHeap
=== RUN   TestUploadHeap/Basic
=== RUN   TestUploadHeap/managedAddChunkToHeap
=== RUN   TestUploadHeap/managedBuildChunkHeap
=== RUN   TestUploadHeap/managedBuildUnfinishedChunks
=== RUN   TestUploadHeap/managedPushChunkForRepair
=== RUN   TestUploadHeap/managedTryUpdate
=== RUN   TestUploadHeap/AddChunksToHeapPanic
=== RUN   TestUploadHeap/AddDirectories
=== RUN   TestUploadHeap/HeapMaps
=== RUN   TestUploadHeap/PauseChan
=== RUN   TestUploadHeap/RemoteChunks
=== RUN   TestUploadHeap/Regression_SwitchStuckStatus
--- PASS: TestUploadHeap (16.52s)
    --- PASS: TestUploadHeap/Basic (1.47s)
    --- PASS: TestUploadHeap/managedAddChunkToHeap (1.95s)
    --- PASS: TestUploadHeap/managedBuildChunkHeap (1.49s)
    --- PASS: TestUploadHeap/managedBuildUnfinishedChunks (1.54s)
    --- PASS: TestUploadHeap/managedPushChunkForRepair (1.63s)
    --- PASS: TestUploadHeap/managedTryUpdate (1.05s)
    --- PASS: TestUploadHeap/AddChunksToHeapPanic (0.90s)
    --- PASS: TestUploadHeap/AddDirectories (1.53s)
    --- PASS: TestUploadHeap/HeapMaps (1.51s)
    --- PASS: TestUploadHeap/PauseChan (0.00s)
    --- PASS: TestUploadHeap/RemoteChunks (1.95s)
    --- PASS: TestUploadHeap/Regression_SwitchStuckStatus (1.48s)
PASS
coverage: 14.9% of statements
ok  	gitlab.com/NebulousLabs/Sia/modules/renter	16.619s	coverage: 14.9% of statements

Checklist

Review and complete the checklist to ensure that the MR is complete before assigned to an approver.

  • All new methods or updated methods have clear docstrings
  • Testing added or updated for new methods
  • Any new packages are added to Makefile and .gitlab-ci.yml
  • API documentation updated for API updates
  • Module README.md updated for changes to workflow
  • Issue added to Sia-UI repo for new supporting features
  • Changelog File Created

Issues Closed

One of many if approved that will go towards #4498

Merge request reports