Skip to content

Commit

Permalink
Enable golint / gofmt checks at make time (cadence-workflow#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkat1109 authored May 16, 2017
1 parent a819aee commit 6accf7e
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 63 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cadence-cassandra-tool: vendor/glide.updated $(TOOLS_SRC)
cadence: vendor/glide.updated main.go
go build -i -o cadence main.go

bins_nothrift: cadence-cassandra-tool cadence
bins_nothrift: lint cadence-cassandra-tool cadence

bins: thriftc bins_nothrift

Expand Down Expand Up @@ -116,6 +116,22 @@ cover: cover_profile
cover_ci: cover_profile
goveralls -coverprofile=$(BUILD)/cover.out -service=travis-ci || echo -e "\x1b[31mCoveralls failed\x1b[m"; \

lint:
@lintFail=0; for file in $(ALL_SRC); do \
golint -set_exit_status "$$file"; \
if [ $$? -eq 1 ]; then lintFail=1; fi; \
done; \
if [ $$lintFail -eq 1 ]; then exit 1; fi;
@OUTPUT=`gofmt -l $(ALL_SRC) 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "Run 'make fmt'. gofmt must be run on the following files:"; \
echo "$$OUTPUT"; \
exit 1; \
fi

fmt:
@gofmt -w $(ALL_SRC)

clean:
rm -f cadence
rm -f cadence-cassandra-tool
Expand Down
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ const (
type (
// EncodingType is an enum that represents various data encoding types
EncodingType string
)
)
6 changes: 3 additions & 3 deletions common/metrics/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (

// Service names for all services that emit metrics.
const (
Common = iota
Common = iota
Frontend
History
Matching
Expand Down Expand Up @@ -350,7 +350,7 @@ var ScopeDefs = map[ServiceIdx]map[int]scopeDefinition{

// Common Metrics enum
const (
CadenceRequests = iota
CadenceRequests = iota
CadenceFailures
CadenceLatency
CadenceErrBadRequestCounter
Expand All @@ -370,7 +370,7 @@ const (

// History Metrics enum
const (
TransferTasksProcessedCounter = iota + NumCommonMetrics
TransferTasksProcessedCounter = iota + NumCommonMetrics
MultipleCompletionDecisionsCounter
CadenceErrEventAlreadyStartedCounter
CadenceErrShardOwnershipLostCounter
Expand Down
6 changes: 3 additions & 3 deletions common/persistence/cassandraMetadataPersistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ const (

templateUpdateDomainQuery = `UPDATE domains ` +
`SET domain = ` + templateDomainType + `, ` +
`config = ` + templateDomainConfigType + ` ` +
`config = ` + templateDomainConfigType + ` ` +
`WHERE id = ?`

templateUpdateDomainByNameQuery = `UPDATE domains_by_name ` +
`SET domain = ` + templateDomainType + `, ` +
`config = ` + templateDomainConfigType + ` ` +
`config = ` + templateDomainConfigType + ` ` +
`WHERE name = ?`

templateDeleteDomainQuery = `DELETE FROM domains ` +
Expand All @@ -87,7 +87,7 @@ type (
}
)

// NewCassandraHistoryPersistence is used to create an instance of HistoryManager implementation
// NewCassandraMetadataPersistence is used to create an instance of HistoryManager implementation
func NewCassandraMetadataPersistence(hosts string, dc string, keyspace string, logger bark.Logger) (MetadataManager,
error) {
cluster := common.NewCassandraCluster(hosts, dc)
Expand Down
3 changes: 1 addition & 2 deletions common/persistence/cassandraMetadataPersistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ func (m *metadataPersistenceSuite) UpdateDomain(info *DomainInfo, config *Domain
func (m *metadataPersistenceSuite) DeleteDomain(id, name string) error {
if len(id) > 0 {
return m.MetadataManager.DeleteDomain(&DeleteDomainRequest{ID: id})
} else {
return m.MetadataManager.DeleteDomainByName(&DeleteDomainByNameRequest{Name: name})
}
return m.MetadataManager.DeleteDomainByName(&DeleteDomainByNameRequest{Name: name})
}
16 changes: 8 additions & 8 deletions common/persistence/cassandraPersistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,14 @@ func (s *cassandraPersistenceSuite) TestWorkflowMutableState_Activities() {
currentTime := time.Now().UTC()
activityInfos := []*ActivityInfo{
{
ScheduleID: 1,
ScheduledEvent: []byte("scheduled_event_1"),
StartedID: 2,
StartedEvent: []byte("started_event_1"),
ScheduleToCloseTimeout: 1,
ScheduleToStartTimeout: 2,
StartToCloseTimeout: 3,
HeartbeatTimeout: 4,
ScheduleID: 1,
ScheduledEvent: []byte("scheduled_event_1"),
StartedID: 2,
StartedEvent: []byte("started_event_1"),
ScheduleToCloseTimeout: 1,
ScheduleToStartTimeout: 2,
StartToCloseTimeout: 3,
HeartbeatTimeout: 4,
LastHeartBeatUpdatedTime: currentTime,
}}
err2 := s.UpdateWorkflowExecution(updatedInfo, []int64{int64(4)}, nil, int64(3), nil, nil, activityInfos, nil, nil, nil)
Expand Down
1 change: 1 addition & 0 deletions common/persistence/historySerializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type (
)

const (
// DefaultEncodingType is the default encoding format for persisted history
DefaultEncodingType = common.EncodingTypeJSON
)

Expand Down
4 changes: 2 additions & 2 deletions common/persistence/persistenceMetricClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewHistoryPersistenceClient(persistence HistoryManager, m3Client metrics.Cl
}
}

// NewHistoryPersistenceClient creates a HistoryManager client to manage workflow execution history
// NewMetadataPersistenceClient creates a HistoryManager client to manage workflow execution history
func NewMetadataPersistenceClient(persistence MetadataManager, m3Client metrics.Client) MetadataManager {
return &metadataPersistenceClient{
persistence: persistence,
Expand Down Expand Up @@ -517,4 +517,4 @@ func (p *metadataPersistenceClient) updateErrorMetric(scope int, err error) {
default:
p.m3Client.IncCounter(scope, metrics.PersistenceFailures)
}
}
}
1 change: 1 addition & 0 deletions common/persistence/persistenceTestBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (s *TestBase) GetWorkflowExecutionInfo(domainID string, workflowExecution w
return response.State, nil
}

// GetCurrentWorkflow returns the workflow state for the given params
func (s *TestBase) GetCurrentWorkflow(domainID, workflowID string) (string, error) {
response, err := s.WorkflowMgr.GetCurrentExecution(&GetCurrentExecutionRequest{
DomainID: domainID,
Expand Down
10 changes: 5 additions & 5 deletions host/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ func (s *integrationSuite) TestRequestCancelWorkflowDecisionExecution() {
s.Nil(err)

cancellationSent := false
intiatedEventId := 10
intiatedEventID := 10
CheckHistoryLoopForCancelSent:
for i := 1; i < 10; i++ {
historyResponse, err := s.engine.GetWorkflowExecutionHistory(&workflow.GetWorkflowExecutionHistoryRequest{
Expand All @@ -1773,7 +1773,7 @@ CheckHistoryLoopForCancelSent:
}

externalWorkflowExecutionCancelRequestedEvent := lastEvent.GetExternalWorkflowExecutionCancelRequestedEventAttributes()
s.Equal(int64(intiatedEventId), externalWorkflowExecutionCancelRequestedEvent.GetInitiatedEventId())
s.Equal(int64(intiatedEventID), externalWorkflowExecutionCancelRequestedEvent.GetInitiatedEventId())
s.Equal(id, externalWorkflowExecutionCancelRequestedEvent.GetWorkflowExecution().GetWorkflowId())
s.Equal(we2.GetRunId(), externalWorkflowExecutionCancelRequestedEvent.GetWorkflowExecution().GetRunId())

Expand Down Expand Up @@ -1823,7 +1823,7 @@ GetHistoryLoop:

s.NotNil(cancelRequestEvent)
cancelRequestEventAttributes := cancelRequestEvent.GetWorkflowExecutionCancelRequestedEventAttributes()
s.Equal(int64(intiatedEventId), cancelRequestEventAttributes.GetExternalInitiatedEventId())
s.Equal(int64(intiatedEventID), cancelRequestEventAttributes.GetExternalInitiatedEventId())
s.Equal(id, cancelRequestEventAttributes.GetExternalWorkflowExecution().GetWorkflowId())
s.Equal(we.GetRunId(), cancelRequestEventAttributes.GetExternalWorkflowExecution().GetRunId())

Expand Down Expand Up @@ -1920,7 +1920,7 @@ func (s *integrationSuite) TestRequestCancelWorkflowDecisionExecution_UnKnownTar
s.Nil(err)

cancellationSentFailed := false
intiatedEventId := 10
intiatedEventID := 10
CheckHistoryLoopForCancelSent:
for i := 1; i < 10; i++ {
historyResponse, err := s.engine.GetWorkflowExecutionHistory(&workflow.GetWorkflowExecutionHistoryRequest{
Expand All @@ -1942,7 +1942,7 @@ CheckHistoryLoopForCancelSent:
}

requestCancelExternalWorkflowExecutionFailedEvetn := lastEvent.GetRequestCancelExternalWorkflowExecutionFailedEventAttributes()
s.Equal(int64(intiatedEventId), requestCancelExternalWorkflowExecutionFailedEvetn.GetInitiatedEventId())
s.Equal(int64(intiatedEventID), requestCancelExternalWorkflowExecutionFailedEvetn.GetInitiatedEventId())
s.Equal("workflow_not_exist", requestCancelExternalWorkflowExecutionFailedEvetn.GetWorkflowExecution().GetWorkflowId())
s.Equal(we.GetRunId(), requestCancelExternalWorkflowExecutionFailedEvetn.GetWorkflowExecution().GetRunId())

Expand Down
13 changes: 13 additions & 0 deletions service/frontend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (wh *WorkflowHandler) IsHealthy(ctx thrift.Context) (bool, error) {
return true, nil
}

// RegisterDomain creates a new domain which can be used as a container for all resources. Domain is a top level
// entity within Cadence, used as a container for all resources like workflow executions, tasklists, etc. Domain
// acts as a sandbox and provides isolation for all resources within the domain. All resources belongs to exactly one
// domain.
func (wh *WorkflowHandler) RegisterDomain(ctx thrift.Context, registerRequest *gen.RegisterDomainRequest) error {
wh.startWG.Wait()

Expand All @@ -140,6 +144,7 @@ func (wh *WorkflowHandler) RegisterDomain(ctx thrift.Context, registerRequest *g
return nil
}

// DescribeDomain returns the information and configuration for a registered domain.
func (wh *WorkflowHandler) DescribeDomain(ctx thrift.Context,
describeRequest *gen.DescribeDomainRequest) (*gen.DescribeDomainResponse, error) {
wh.startWG.Wait()
Expand All @@ -162,6 +167,7 @@ func (wh *WorkflowHandler) DescribeDomain(ctx thrift.Context,
return response, nil
}

// UpdateDomain is used to update the information and configuration for a registered domain.
func (wh *WorkflowHandler) UpdateDomain(ctx thrift.Context,
updateRequest *gen.UpdateDomainRequest) (*gen.UpdateDomainResponse, error) {
wh.startWG.Wait()
Expand Down Expand Up @@ -216,6 +222,9 @@ func (wh *WorkflowHandler) UpdateDomain(ctx thrift.Context,
return response, nil
}

// DeprecateDomain us used to update status of a registered domain to DEPRECATED. Once the domain is deprecated
// it cannot be used to start new workflow executions. Existing workflow executions will continue to run on
// deprecated domains.
func (wh *WorkflowHandler) DeprecateDomain(ctx thrift.Context, deprecateRequest *gen.DeprecateDomainRequest) error {
wh.startWG.Wait()

Expand Down Expand Up @@ -553,6 +562,8 @@ func (wh *WorkflowHandler) GetWorkflowExecutionHistory(
return response, nil
}

// SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
// WorkflowExecutionSignaled event recorded in the history and a decision task being created for the execution.
func (wh *WorkflowHandler) SignalWorkflowExecution(ctx thrift.Context,
signalRequest *gen.SignalWorkflowExecutionRequest) error {
wh.startWG.Wait()
Expand Down Expand Up @@ -592,6 +603,8 @@ func (wh *WorkflowHandler) SignalWorkflowExecution(ctx thrift.Context,
return wrapError(err)
}

// TerminateWorkflowExecution terminates an existing workflow execution by recording WorkflowExecutionTerminated event
// in the history and immediately terminating the execution instance.
func (wh *WorkflowHandler) TerminateWorkflowExecution(ctx thrift.Context,
terminateRequest *gen.TerminateWorkflowExecutionRequest) error {
wh.startWG.Wait()
Expand Down
4 changes: 4 additions & 0 deletions service/history/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ func (h *Handler) RequestCancelWorkflowExecution(ctx thrift.Context,
return nil
}

// SignalWorkflowExecution is used to send a signal event to running workflow execution. This results in
// WorkflowExecutionSignaled event recorded in the history and a decision task being created for the execution.
func (h *Handler) SignalWorkflowExecution(ctx thrift.Context,
wrappedRequest *hist.SignalWorkflowExecutionRequest) error {
h.startWG.Wait()
Expand Down Expand Up @@ -496,6 +498,8 @@ func (h *Handler) SignalWorkflowExecution(ctx thrift.Context,
return nil
}

// TerminateWorkflowExecution terminates an existing workflow execution by recording WorkflowExecutionTerminated event
// in the history and immediately terminating the execution instance.
func (h *Handler) TerminateWorkflowExecution(ctx thrift.Context,
wrappedRequest *hist.TerminateWorkflowExecutionRequest) error {
h.startWG.Wait()
Expand Down
42 changes: 21 additions & 21 deletions service/history/historyBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *historyBuilderSuite) TestHistoryBuilderDynamicSuccess() {
taskTimeout := int32(10)
we := workflow.WorkflowExecution{
WorkflowId: common.StringPtr(id),
RunId: common.StringPtr(rid),
RunId: common.StringPtr(rid),
}

workflowStartedEvent := s.addWorkflowExecutionStartedEvent(we, wt, tl, input, execTimeout, taskTimeout, identity)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (s *historyBuilderSuite) TestHistoryBuilderWorkflowStartFailures() {
taskTimeout := int32(10)
we := workflow.WorkflowExecution{
WorkflowId: common.StringPtr(id),
RunId: common.StringPtr(rid),
RunId: common.StringPtr(rid),
}

workflowStartedEvent := s.addWorkflowExecutionStartedEvent(we, wt, tl, input, execTimeout, taskTimeout, identity)
Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *historyBuilderSuite) TestHistoryBuilderDecisionScheduledFailures() {
taskTimeout := int32(10)
we := workflow.WorkflowExecution{
WorkflowId: common.StringPtr(id),
RunId: common.StringPtr(rid),
RunId: common.StringPtr(rid),
}

workflowStartedEvent := s.addWorkflowExecutionStartedEvent(we, wt, tl, input, execTimeout, taskTimeout, identity)
Expand Down Expand Up @@ -263,7 +263,7 @@ func (s *historyBuilderSuite) TestHistoryBuilderDecisionStartedFailures() {
taskTimeout := int32(10)
we := workflow.WorkflowExecution{
WorkflowId: common.StringPtr(id),
RunId: common.StringPtr(rid),
RunId: common.StringPtr(rid),
}

workflowStartedEvent := s.addWorkflowExecutionStartedEvent(we, wt, tl, input, execTimeout, taskTimeout, identity)
Expand Down Expand Up @@ -314,10 +314,10 @@ func (s *historyBuilderSuite) addWorkflowExecutionStartedEvent(we workflow.Workf
taskList string, input []byte, executionStartToCloseTimeout, taskStartToCloseTimeout int32,
identity string) *workflow.HistoryEvent {
e := s.msBuilder.AddWorkflowExecutionStartedEvent(s.domainID, we, &workflow.StartWorkflowExecutionRequest{
WorkflowId: common.StringPtr(we.GetWorkflowId()),
WorkflowType: &workflow.WorkflowType{Name: common.StringPtr(workflowType)},
TaskList: &workflow.TaskList{Name: common.StringPtr(taskList)},
Input: input,
WorkflowId: common.StringPtr(we.GetWorkflowId()),
WorkflowType: &workflow.WorkflowType{Name: common.StringPtr(workflowType)},
TaskList: &workflow.TaskList{Name: common.StringPtr(taskList)},
Input: input,
ExecutionStartToCloseTimeoutSeconds: common.Int32Ptr(executionStartToCloseTimeout),
TaskStartToCloseTimeoutSeconds: common.Int32Ptr(taskStartToCloseTimeout),
Identity: common.StringPtr(identity),
Expand Down Expand Up @@ -351,18 +351,18 @@ func (s *historyBuilderSuite) addDecisionTaskCompletedEvent(scheduleID, startedI
}

func (s *historyBuilderSuite) addActivityTaskScheduledEvent(decisionCompletedID int64, activityID, activityType,
taskList string, input []byte, timeout, queueTimeout, hearbeatTimeout int32) (*workflow.HistoryEvent,
taskList string, input []byte, timeout, queueTimeout, hearbeatTimeout int32) (*workflow.HistoryEvent,
*persistence.ActivityInfo) {
return s.msBuilder.AddActivityTaskScheduledEvent(decisionCompletedID,
&workflow.ScheduleActivityTaskDecisionAttributes{
ActivityId: common.StringPtr(activityID),
ActivityType: &workflow.ActivityType{Name: common.StringPtr(activityType)},
TaskList: &workflow.TaskList{Name: common.StringPtr(taskList)},
Input: input,
ScheduleToCloseTimeoutSeconds: common.Int32Ptr(timeout),
ScheduleToStartTimeoutSeconds: common.Int32Ptr(queueTimeout),
HeartbeatTimeoutSeconds: common.Int32Ptr(hearbeatTimeout),
})
ActivityId: common.StringPtr(activityID),
ActivityType: &workflow.ActivityType{Name: common.StringPtr(activityType)},
TaskList: &workflow.TaskList{Name: common.StringPtr(taskList)},
Input: input,
ScheduleToCloseTimeoutSeconds: common.Int32Ptr(timeout),
ScheduleToStartTimeoutSeconds: common.Int32Ptr(queueTimeout),
HeartbeatTimeoutSeconds: common.Int32Ptr(hearbeatTimeout),
})
}

func (s *historyBuilderSuite) addActivityTaskStartedEvent(scheduleID int64, taskList,
Expand Down Expand Up @@ -398,7 +398,7 @@ func (s *historyBuilderSuite) addActivityTaskFailedEvent(scheduleID, startedID i
}

func (s *historyBuilderSuite) validateWorkflowExecutionStartedEvent(event *workflow.HistoryEvent, workflowType,
taskList string, input []byte, executionStartToCloseTimeout, taskStartToCloseTimeout int32, identity string) {
taskList string, input []byte, executionStartToCloseTimeout, taskStartToCloseTimeout int32, identity string) {
s.NotNil(event)
s.Equal(workflow.EventType_WorkflowExecutionStarted, event.GetEventType())
s.Equal(firstEventID, event.GetEventId())
Expand Down Expand Up @@ -435,7 +435,7 @@ func (s *historyBuilderSuite) validateDecisionTaskStartedEvent(event *workflow.H
}

func (s *historyBuilderSuite) validateDecisionTaskCompletedEvent(event *workflow.HistoryEvent, eventID,
scheduleID, startedID int64, context []byte, identity string) {
scheduleID, startedID int64, context []byte, identity string) {
s.NotNil(event)
s.Equal(workflow.EventType_DecisionTaskCompleted, event.GetEventType())
s.Equal(eventID, event.GetEventId())
Expand Down Expand Up @@ -476,7 +476,7 @@ func (s *historyBuilderSuite) validateActivityTaskStartedEvent(event *workflow.H
}

func (s *historyBuilderSuite) validateActivityTaskCompletedEvent(event *workflow.HistoryEvent, eventID,
scheduleID, startedID int64, result []byte, identity string) {
scheduleID, startedID int64, result []byte, identity string) {
s.NotNil(event)
s.Equal(workflow.EventType_ActivityTaskCompleted, event.GetEventType())
s.Equal(eventID, event.GetEventId())
Expand All @@ -489,7 +489,7 @@ scheduleID, startedID int64, result []byte, identity string) {
}

func (s *historyBuilderSuite) validateActivityTaskFailedEvent(event *workflow.HistoryEvent, eventID,
scheduleID, startedID int64, reason string, details []byte, identity string) {
scheduleID, startedID int64, reason string, details []byte, identity string) {
s.NotNil(event)
s.Equal(workflow.EventType_ActivityTaskFailed, event.GetEventType())
s.Equal(eventID, event.GetEventId())
Expand Down
Loading

0 comments on commit 6accf7e

Please sign in to comment.