Skip to content

Commit

Permalink
Junk files
Browse files Browse the repository at this point in the history
Signed-off-by: s8sg <swarvanusg@gmail.com>
  • Loading branch information
s8sg committed Jul 16, 2023
1 parent e78fa2f commit d95a649
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 22 deletions.
35 changes: 30 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
INTEGRATION_TEST_PATH?=./integration-test
EXAMPLES_PATH?=./samples

.PHONY: build
all: coverage
all: build coverage

build: | __go-pkg-list
@go build --ldflags "-s -w" -a -installsuffix cgo ${GO_PKG_LIST}

## coverage: Generate global code coverage report
.PHONY: coverage
coverage: | __go-pkg-list
@go test -gcflags=-l -v ${GO_PKG_LIST} -coverprofile /tmp/pls_cp.out || true
coverage: | __go-pkg-list unit integration
@go tool cover -html=/tmp/pls_cp.out -o /tmp/coverage.html
@echo "You can find coverage report at /tmp/coverage.html"

## coverage: Generate global code coverage report
.PHONY: unit
test.unit: | __go-pkg-list
@go test -tags=unit -gcflags=-l -v ${GO_PKG_LIST} -coverprofile /tmp/pls_cp.out


## Run integration test
.PHONY: integration
test.integration:
go test -tags=integration $(INTEGRATION_TEST_PATH) $(EXAMPLES_PATH) -count=1 -v -coverprofile /tmp/pls_cp.out

## docker.start: Starts docker compose
docker.start:
@docker-compose up -d

## docker.start: Starts docker compose
docker.stop:
@docker-compose down

__go-pkg-list:
ifeq ($(origin GO_PKG_LIST), undefined)
$(eval GO_PKG_LIST ?= $(shell go list ./... | grep -v /doc/ | grep -v /template/ | grep -v /vendor/))
endif
$(eval GO_PKG_LIST ?= $(shell go list ./... | grep -v /doc/ | grep -v /template/ | grep -v /vendor/ | grep -v samples | grep -v integration-test))
endif
2 changes: 2 additions & 0 deletions integration-test/test_goflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package test

1 change: 1 addition & 0 deletions runtime/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Router(fRuntime *FlowRuntime) http.Handler {
router.POST("flow/:"+FlowNameParamName+"/request/resume:"+RequestIdParamName, resumeRequestHandler(fRuntime))
router.POST("flow/:"+FlowNameParamName+"/request/state:"+RequestIdParamName, requestStateHandler(fRuntime))
router.POST("flow/:"+FlowNameParamName+"/request/list", requestListHandler(fRuntime))
// TODO: Add health check endpoint

return router
}
36 changes: 20 additions & 16 deletions samples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ import (
goflow "github.com/s8sg/goflow/v1"
)

func GetFlowService() *goflow.FlowService {
fs := &goflow.FlowService{
Port: 8080,
RedisURL: "localhost:6379",
RedisPassword: "redis",
OpenTraceUrl: "localhost:5775",
WorkerConcurrency: 5,
EnableMonitoring: true,
DebugEnabled: true,
}
fs.Register("single", single.DefineWorkflow)
fs.Register("serial", serial.DefineWorkflow)
fs.Register("parallel", parallel.DefineWorkflow)
fs.Register("condition", condition.DefineWorkflow)
fs.Register("loop", loop.DefineWorkflow)
fs.Register("myflow", myflow.DefineWorkflow)
return fs
}

func main() {
fs := &goflow.FlowService{
Port: 8080,
RedisURL: "localhost:6379",
RedisPassword: "redis",
OpenTraceUrl: "localhost:5775",
WorkerConcurrency: 5,
EnableMonitoring: true,
DebugEnabled: true,
}
fs.Register("single", single.DefineWorkflow)
fs.Register("serial", serial.DefineWorkflow)
fs.Register("parallel", parallel.DefineWorkflow)
fs.Register("condition", condition.DefineWorkflow)
fs.Register("loop", loop.DefineWorkflow)
fs.Register("myflow", myflow.DefineWorkflow)
fmt.Println(fs.Start())
fmt.Println(GetFlowService().Start())
}
50 changes: 50 additions & 0 deletions samples/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"testing"
"net/http"
"github.com/stretchr/testify/assert"
"time"
"log"
)



func runExamplesServer() {
go func() {
fs := GetFlowService()
log.Fatalf(fs.Start().Error())
}()
}

func waitForServer() {
backoff := 50 * time.Millisecond
log.Printf("waiting for server to start")
for i := 0; i < 10; i++ {
// TODO: Add health check endpoint
_, err := http.Get("http://localhost:8080/flow/single")
if err != nil {
time.Sleep(backoff)
continue
}
log.Printf("server started")
return
}
log.Fatalf("Server on localhost:8080 not up after 10 attempts")
}


func Test_single_flow_execution(t *testing.T) {
runExamplesServer()
waitForServer()

t.Run("it should return 200 when executing single flow", func(t *testing.T) {
resp, err := http.Get("http://localhost:8080/flow/single")

if err != nil {
t.Fatalf("Expected no error, got %v", err)
}

assert.Equal(t, 200, resp.StatusCode)
})
}
1 change: 0 additions & 1 deletion v1/goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (fs *FlowService) StartServer() error {
if err := fs.initRuntime(); err != nil {
return err
}
go fs.runtimeWorker(errorChan)
go fs.server(errorChan)
err := <-errorChan
return fmt.Errorf("server has stopped, error: %v", err)
Expand Down

0 comments on commit d95a649

Please sign in to comment.