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

Service provider. Removes global services and passing services around. #61

Merged
merged 15 commits into from
Aug 2, 2018

Conversation

Skarlso
Copy link
Member

@Skarlso Skarlso commented Jul 27, 2018

No description provided.

err := storeService.Init()
if err != nil {
gaia.Cfg.Logger.Error("cannot initialize store", "error", err.Error())
os.Exit(1)
Copy link
Member Author

Choose a reason for hiding this comment

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

Ups, this shouldn't be os.Exit(1) here but rather return an error.

@michelvocks
Copy link
Member

I like that a lot. 😄

Currently, it feels a bit weird to pass around several instances of services. It also allows us to remove the public instance of store in handlers which is great.

Some notes from my side:

  • We should add new interfaces for store and scheduler and provide mock-functions so that we can test with mocks.
  • What do you think about moving var schedulerService *scheduler.Scheduler and var storeService *store.Store into the type Provider struct{} struct? We could also remove type Provider struct{} completely but I'm not quite sure what happens when we, for example, run tests in parallel? This might add a race condition.
  • We should add every service.

Anyway, good job so far! ❤️

@al3rez
Copy link
Contributor

al3rez commented Jul 27, 2018

awesome! this makes it easier to write test.

@codecov-io
Copy link

codecov-io commented Jul 27, 2018

Codecov Report

Merging #61 into master will increase coverage by 2.66%.
The diff coverage is 53.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   57.37%   60.03%   +2.66%     
==========================================
  Files          17       18       +1     
  Lines        1492     1544      +52     
==========================================
+ Hits          856      927      +71     
+ Misses        539      510      -29     
- Partials       97      107      +10
Impacted Files Coverage Δ
pipeline/ticker.go 0% <0%> (ø) ⬆️
handlers/pipeline_run.go 0% <0%> (ø) ⬆️
handlers/vault.go 63.63% <100%> (+4.26%) ⬆️
handlers/handler.go 84.05% <100%> (-0.45%) ⬇️
pipeline/create_pipeline.go 52.83% <100%> (+52.83%) ⬆️
security/vault.go 76.51% <100%> (ø) ⬆️
pipeline/build_golang.go 100% <100%> (ø) ⬆️
scheduler/scheduler.go 62.16% <100%> (ø) ⬆️
store/store.go 67.34% <100%> (ø) ⬆️
pipeline/build_java.go 92.5% <100%> (+0.19%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac87e63...6b832ea. Read the comment docs.

@Skarlso
Copy link
Member Author

Skarlso commented Jul 28, 2018

@azbshiri @michelvocks I think you guys going to like this. ;) Take a look here at the mocked database test. https://github.com/gaia-pipeline/gaia/pull/61/files#diff-984f2526ba5ed92156cfe03873689506R285

With this we'll be able to completely remove all database dependency from all tests and use a mock.

Expect for the store tests which can be left alone as integration tests. :)

store/store.go Outdated

// Provides an embeddable interface so that not all of the methods need
// to be overriden in case of a Mock.
var _ GaiaStore = (*BoltStore)(nil)
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 is pure magic right here. Allows for an embeddable type so that you don't have to implement every function in order to use a mock. Just the ones you would like to mock out like I'm demonstrating in the build_pipeline test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually no hahahahaha. :D I thought about this some more and it made no sense that it would influence embedability. This is just compile time interface compliance check for BoltStore. If boltstore would miss a function this line here wouldn't compile. Still neat that partial interface embedding works out of the box.

@Skarlso Skarlso changed the title POC for a service provider. Removes global services and passing services around. [WIP] Service provider. Removes global services and passing services around. Jul 28, 2018
@Skarlso
Copy link
Member Author

Skarlso commented Jul 29, 2018

Scheduler is now also behind an interface. This made me able to write three additional tests for handlers which further increased coverage.
https://github.com/gaia-pipeline/gaia/pull/61/files#diff-90d173722cbe909bc107fb57496d9dc2R276

@michelvocks
Copy link
Member

Lovely! 🤗

@Skarlso
Copy link
Member Author

Skarlso commented Aug 1, 2018

Waiting for #60 to go in. After that, refactor and it should be ready to be merged.

Also, once Java support is merged, I'll increase the test coverage with the help of the service provider.

@Skarlso
Copy link
Member Author

Skarlso commented Aug 1, 2018

Alright, stuff is merged. Now doing the cleanup... :P

@Skarlso Skarlso changed the title [WIP] Service provider. Removes global services and passing services around. Service provider. Removes global services and passing services around. Aug 1, 2018
@Skarlso Skarlso added the Ready To Merge PR is ready to be merged into master label Aug 1, 2018
@Skarlso Skarlso requested a review from michelvocks August 1, 2018 21:12
@Skarlso
Copy link
Member Author

Skarlso commented Aug 1, 2018

Doneeeeeeeeee 🎉

@michelvocks So this should be now ready to be merged. I increased the coverage too. There are some fringe cases that could still be covered though. But I want to unblock other PRs first, and then add more tests there.

What say you? Also, if you are wondering why the error is ignored from the services, that's because of the singleton. All the services are initialised in the main function. If they don't work, the main function exits with os.Exit(1). This means the rest of the application is safe, since from there on the singleton is returned always.

@michelvocks
Copy link
Member

Well done, @Skarlso 🤗
2,66% test coverage increase and around 200~ Lines deleted, this simply warms my heart ❤️
LGTM 🎉

@michelvocks michelvocks merged commit 81d8f41 into gaia-pipeline:master Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready To Merge PR is ready to be merged into master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants