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

Datastore refactor and added postgres tests #259

Merged
merged 4 commits into from
Nov 14, 2016
Merged

Conversation

pedronasser
Copy link
Contributor

@pedronasser pedronasser commented Nov 10, 2016

  • Changed datastore's StoreApp and StoreRoute to InsertApp/UpdateApp and InsertRoute/UpdateRoute
  • Added postgres tests and fixed boltdb tests
  • Added/fixed argument validations to datastore
  • Added test-datastore to makefile and to circleci
  • Prevented datastore tests to run in test-docker

fixes #252 #253 #254

Copy link
Contributor

@ucirello ucirello left a comment

Choose a reason for hiding this comment

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

It is basically implementing the solution, but I do see some problems:

1 - It seems it does not handle concurrent cases correctly (two requests with the similar params might trigger two databases writes).

2 - I think it is worth double checking fnctl - I know it tests against 400. So it lacks tests for 409s.

return
}

app, err = Api.Datastore.StoreApp(wapp.App)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does it happen when two competing requests execute the same request in this case?

return
}
if app != nil {
c.JSON(http.StatusConflict, simpleError(models.ErrAppsAlreadyExists))
Copy link
Contributor

Choose a reason for hiding this comment

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

How would the client libraries react to 409? Have you tested fnctl? I think it might need some extra tests there to handle 409 responses.

@ucirello ucirello added this to the Alpha 2 milestone Nov 11, 2016
@pedronasser pedronasser changed the title fix apps & routes creation/update [WIP] fix apps & routes creation/update Nov 11, 2016
@pedronasser pedronasser changed the title [WIP] fix apps & routes creation/update Datastore refactor and added postgres tests Nov 14, 2016
Copy link
Contributor

@ucirello ucirello left a comment

Choose a reason for hiding this comment

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

In my opinion, it addresses the problem correctly. There some minor details that I think we'd need to fix before merging it.

@@ -14,15 +14,18 @@ build-docker:
docker build -t iron/functions:latest .

test:
go test -v $(shell glide nv | grep -v examples | grep -v tool | grep -v fnctl)
go test -v $(shell go list ./... | grep -v vendor | grep -v examples | grep -v tool | grep -v fnctl)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the replacement between glide and go list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because glide nv doesn't get the list of all packages.
In the test-docker I had to ignore the datastore package.
In this command we could continue using glide nv but I think is good to use the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this command we could continue using glide nv but I think is good to use the same.

If we could, then again, why change?

test-docker:
docker run -ti --privileged --rm -e LOG_LEVEL=debug \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(DIR):/go/src/github.com/iron-io/functions \
-w /go/src/github.com/iron-io/functions iron/go:dev go test \
-v $(shell glide nv | grep -v examples | grep -v tool | grep -v fnctl)
-v $(shell go list ./... | grep -v vendor | grep -v examples | grep -v tool | grep -v fnctl | grep -v datastore)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

glide nv will list all (n)on-(v)endored dependencies... See previous comment.

return err
}

// Update app fields
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a necessary comment?

if err != nil {
return err
}
// Update route fields
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto for the comment

@@ -21,15 +21,16 @@ func setLogBuffer() *bytes.Buffer {
return &buf
}

const tmpBolt = "/tmp/func_test_bolt.db"
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason for not using ioutil.TempFile?

@@ -125,17 +182,29 @@ func (ds *PostgresDatastore) GetApp(name string) (*models.App, error) {
json.Unmarshal([]byte(config), &res.Config)

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

    if err == sql.ErrNoRows {
        return nil, models.ErrAppsNotFound
    } else if err != nil {
        return nil, err
    }

}
}

func TestPostgres(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This provides appropriate coverage, although it is just a very long test. We're Go1.7 now, could we perhaps refactor it into subtests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ccirello Can we do that in another PR?
I'm also thinking about moving theses tests inside their directories.
Like: moving postgres_test.go to postgres dir.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure.

@@ -53,22 +53,23 @@ func handleRouteCreate(c *gin.Context) {
}

if app == nil {
// Create a new application and add the route to that new application
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a necessary comment?

@@ -185,6 +186,8 @@ func (s *Server) bindHandlers() {
engine.NoRoute(handleSpecial)
}

var ErrInternalServerError = errors.New("Something unexpected happened on the server")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not anymore, I'll remove it

@pedronasser pedronasser merged commit 7aa1981 into master Nov 14, 2016
@pedronasser pedronasser deleted the fix-apps-routes-api branch November 14, 2016 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP PUT to /apps/{app} creates new app instead of modifying initial
2 participants