Skip to content

Commit

Permalink
Fix build time on VersionResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Juanjo Alvarez <[email protected]>
  • Loading branch information
Juanjo Alvarez committed Jan 28, 2019
1 parent ac29b44 commit e5ca340
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion cmd/bblfshd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/signal"
"sync"
"syscall"
"time"

"github.com/bblfsh/bblfshd/daemon"
"github.com/bblfsh/bblfshd/runtime"
Expand Down Expand Up @@ -114,7 +115,12 @@ func main() {
os.Exit(1)
}

d := daemon.NewDaemon(version, r, grpcOpts...)
parsedBuild, err := time.Parse(time.RFC3339, build)
if err != nil {
logrus.Errorf("wrong date format for build: %s", err)
os.Exit(1)
}
d := daemon.NewDaemon(version, parsedBuild, r, grpcOpts...)
if args := cmd.Args(); len(args) == 2 && args[0] == "install" && args[1] == "recommended" {
err := installRecommended(d)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"
"sync"
"time"

"github.com/bblfsh/bblfshd/daemon/protocol"
"github.com/bblfsh/bblfshd/runtime"
Expand All @@ -24,6 +25,7 @@ type Daemon struct {
ControlServer *grpc.Server

version string
build time.Time
runtime *runtime.Runtime
driverEnv []string

Expand All @@ -32,12 +34,13 @@ type Daemon struct {
}

// NewDaemon creates a new server based on the runtime with the given version.
func NewDaemon(version string, r *runtime.Runtime, opts ...grpc.ServerOption) *Daemon {
func NewDaemon(version string, build time.Time, r *runtime.Runtime, opts ...grpc.ServerOption) *Daemon {
commonOpt := protocol2.ServerOptions()
opts = append(opts, commonOpt...)

d := &Daemon{
version: version,
build: build,
runtime: r,
pool: make(map[string]*DriverPool),
UserServer: grpc.NewServer(opts...),
Expand Down
4 changes: 3 additions & 1 deletion daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ func buildMockedDaemon(t *testing.T, images ...runtime.DriverImage) (*Daemon, st
}
}

d := NewDaemon("foo", r)
bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00")
require.NoError(err)
d := NewDaemon("foo", bdate, r)

dp := NewDriverPool(func() (Driver, error) {
return newEchoDriver(), nil
Expand Down
2 changes: 1 addition & 1 deletion daemon/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (s *Service) selectPool(ctx context.Context, language, content, filename st
}

func (d *Service) Version(req *protocol1.VersionRequest) *protocol1.VersionResponse {
return &protocol1.VersionResponse{Version: d.daemon.version}
return &protocol1.VersionResponse{Version: d.daemon.version, Build: d.daemon.build}
}

func (d *Service) SupportedLanguages(req *protocol1.SupportedLanguagesRequest) *protocol1.SupportedLanguagesResponse {
Expand Down
5 changes: 5 additions & 0 deletions daemon/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package daemon
import (
"os"
"testing"
"time"

"github.com/stretchr/testify/require"
"gopkg.in/bblfsh/sdk.v1/protocol"
Expand Down Expand Up @@ -46,6 +47,10 @@ func TestServiceVersion(t *testing.T) {
resp := s.Version(&protocol.VersionRequest{})
require.Len(resp.Errors, 0)
require.Equal(resp.Version, "foo")

bdate, err := time.Parse(time.RFC3339, "2019-01-28T16:49:06+01:00")
require.NoError(err)
require.Equal(resp.Build, bdate)
}

func TestControlServiceDriverPoolStates(t *testing.T) {
Expand Down

0 comments on commit e5ca340

Please sign in to comment.