enhance "file lock sync" logic
This commit is contained in:
parent
a2a0880ff7
commit
eeb549518d
@ -96,11 +96,9 @@ func (b *Build) Build() error {
|
||||
log.Printf("go build cmd is: %v", cmd.Args)
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to execute: %v. The error is: %v", cmd.Args, err)
|
||||
return fmt.Errorf("fail to execute: %v, err: %w", cmd.Args, err)
|
||||
}
|
||||
if err = cmd.Wait(); err != nil {
|
||||
log.Errorf("go build failed. The error is: %v", err)
|
||||
return fmt.Errorf("fail to execute: %v, err: %w", cmd.Args, err)
|
||||
}
|
||||
log.Infoln("Go build exit successful.")
|
||||
@ -111,7 +109,6 @@ func (b *Build) Build() error {
|
||||
// the binary name is always same as the directory name of current directory
|
||||
func (b *Build) determineOutputDir(outputDir string) (string, error) {
|
||||
if b.TmpDir == "" {
|
||||
log.Errorf("Can only be called after Build.MvProjectsToTmp(): %v", ErrWrongCallSequence)
|
||||
return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrWrongCallSequence)
|
||||
}
|
||||
|
||||
@ -119,8 +116,8 @@ func (b *Build) determineOutputDir(outputDir string) (string, error) {
|
||||
if outputDir != "" {
|
||||
abs, err := filepath.Abs(outputDir)
|
||||
if err != nil {
|
||||
log.Errorf("Fail to transform the path: %v to absolute path: %v", outputDir, err)
|
||||
return "", err
|
||||
return "", fmt.Errorf("Fail to transform the path: %v to absolute path: %v", outputDir, err)
|
||||
|
||||
}
|
||||
return abs, nil
|
||||
}
|
||||
|
@ -29,18 +29,48 @@ teardown_file() {
|
||||
kill -9 $GOC_PID
|
||||
}
|
||||
|
||||
setup() {
|
||||
goc init
|
||||
}
|
||||
|
||||
@test "test basic goc build command" {
|
||||
cd samples/run_for_several_seconds
|
||||
wait_profile_backend "build1"
|
||||
|
||||
wait_profile_backend "build1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc build --debug --debugcisyncfile ci-sync.bak;
|
||||
info build output: $output
|
||||
info build1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test goc build command without debug" {
|
||||
cd samples/run_for_several_seconds
|
||||
wait_profile_backend "build2"
|
||||
|
||||
wait_profile_backend "build2" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc build --debugcisyncfile ci-sync.bak;
|
||||
info build output: $output
|
||||
info build2 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test goc build in GOPATH project" {
|
||||
info $PWD
|
||||
export GOPATH=$PWD/samples/simple_gopath_project
|
||||
export GO111MODULE=off
|
||||
cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project
|
||||
|
||||
wait_profile_backend "build3" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc build --buildflags="-v" --debug --debugcisyncfile ci-sync.bak;
|
||||
info build3 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -44,19 +44,25 @@ teardown_file() {
|
||||
}
|
||||
|
||||
@test "test basic goc clear command" {
|
||||
wait_profile_backend "clear1"
|
||||
wait_profile_backend "clear1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc clear --debug --debugcisyncfile ci-sync.bak;
|
||||
info clear1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"coverage counter clear call successfully"* ]]
|
||||
[[ "$output" == *""* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test clear another center" {
|
||||
wait_profile_backend "clear2"
|
||||
wait_profile_backend "clear2" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc clear --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak;
|
||||
info clear2 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"coverage counter clear call successfully"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -35,9 +35,16 @@ teardown_file() {
|
||||
kill -9 $GOC_PID
|
||||
}
|
||||
|
||||
setup() {
|
||||
goc init
|
||||
}
|
||||
|
||||
@test "test basic goc cover command" {
|
||||
cd test-temp
|
||||
wait_profile_backend "cover1"
|
||||
|
||||
wait_profile_backend "cover1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc cover --debug --debugcisyncfile ci-sync.bak;
|
||||
info cover1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
@ -46,4 +53,6 @@ teardown_file() {
|
||||
info ls output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"http_cover_apis_auto_generated.go"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
@ -29,41 +29,53 @@ teardown_file() {
|
||||
kill -9 $GOC_PID
|
||||
}
|
||||
|
||||
setup() {
|
||||
goc init
|
||||
}
|
||||
|
||||
@test "test basic goc diff command" {
|
||||
cd samples/diff_samples
|
||||
|
||||
wait_profile_backend "diff1"
|
||||
|
||||
wait_profile_backend "diff1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc diff --new-profile=./new.voc --base-profile=./base.voc --debug --debugcisyncfile ci-sync.bak;
|
||||
info list output: $output
|
||||
info diff1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"qiniu.com/kodo/apiserver/server/main.go | 50.0% | 100.0% | 50.0%"* ]]
|
||||
[[ "$output" == *"Total | 50.0% | 100.0% | 50.0%"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test diff in prow environment with periodic job" {
|
||||
cd samples/diff_samples
|
||||
|
||||
wait_profile_backend "diff2"
|
||||
wait_profile_backend "diff2" &
|
||||
profile_pid=$!
|
||||
|
||||
export JOB_TYPE=periodic
|
||||
|
||||
run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak;
|
||||
info diff1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"do nothing"* ]]
|
||||
}
|
||||
|
||||
@test "test diff in prow environment with postsubmit job" {
|
||||
cd samples/diff_samples
|
||||
|
||||
wait_profile_backend "diff3"
|
||||
|
||||
export JOB_TYPE=postsubmit
|
||||
|
||||
run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak;
|
||||
info diff2 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"do nothing"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test diff in prow environment with postsubmit job" {
|
||||
cd samples/diff_samples
|
||||
|
||||
wait_profile_backend "diff3" &
|
||||
profile_pid=$!
|
||||
|
||||
export JOB_TYPE=postsubmit
|
||||
|
||||
run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak;
|
||||
info diff3 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"do nothing"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -44,9 +44,12 @@ teardown_file() {
|
||||
}
|
||||
|
||||
@test "test init command" {
|
||||
wait_profile_backend "init1"
|
||||
wait_profile_backend "init1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc init --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak;
|
||||
info init output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -29,13 +29,22 @@ teardown_file() {
|
||||
kill -9 $GOC_PID
|
||||
}
|
||||
|
||||
setup() {
|
||||
goc init
|
||||
}
|
||||
|
||||
@test "test basic goc install command" {
|
||||
info $PWD
|
||||
export GOPATH=$PWD/samples/simple_gopath_project
|
||||
export GO111MODULE=off
|
||||
cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project
|
||||
wait_profile_backend "install"
|
||||
|
||||
wait_profile_backend "install" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc install --debug --debugcisyncfile ci-sync.bak;
|
||||
info install output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
@ -36,11 +36,14 @@ teardown_file() {
|
||||
}
|
||||
|
||||
@test "test basic goc list command" {
|
||||
wait_profile_backend "list"
|
||||
wait_profile_backend "list" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc list --debug --debugcisyncfile ci-sync.bak;
|
||||
info list output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"gocc"* ]]
|
||||
[[ "$output" == *"http"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -27,6 +27,10 @@ setup_file() {
|
||||
GOCC_PID=$!
|
||||
sleep 1
|
||||
|
||||
WORKDIR=$PWD
|
||||
cd samples/run_for_several_seconds
|
||||
goc build --center=http://127.0.0.1:60001
|
||||
|
||||
info "goc server started"
|
||||
}
|
||||
|
||||
@ -35,19 +39,41 @@ teardown_file() {
|
||||
kill -9 $GOCC_PID
|
||||
}
|
||||
|
||||
@test "test goc profile to stdout" {
|
||||
wait_profile_backend "profile1"
|
||||
setup() {
|
||||
goc init --center=http://127.0.0.1:60001
|
||||
goc init
|
||||
}
|
||||
|
||||
run gocc profile --debug --debugcisyncfile ci-sync.bak;
|
||||
@test "test goc profile to stdout" {
|
||||
./simple-project 3>&- &
|
||||
SAMPLE_PID=$!
|
||||
sleep 2
|
||||
|
||||
wait_profile_backend "profile1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc profile --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak
|
||||
info $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"mode: count"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
kill -9 $SAMPLE_PID
|
||||
}
|
||||
|
||||
@test "test goc profile to file" {
|
||||
wait_profile_backend "profile2"
|
||||
./simple-project 3>&- &
|
||||
SAMPLE_PID=$!
|
||||
sleep 2
|
||||
|
||||
run gocc profile -o test-profile.bak --debug --debugcisyncfile ci-sync.bak;
|
||||
wait_profile_backend "profile2" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc profile --center=http://127.0.0.1:60001 -o test-profile.bak --debug --debugcisyncfile ci-sync.bak;
|
||||
[ "$status" -eq 0 ]
|
||||
run cat test-profile.bak
|
||||
[[ "$output" == *"mode: count"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
kill -9 $SAMPLE_PID
|
||||
}
|
@ -35,20 +35,31 @@ teardown_file() {
|
||||
kill -9 $GOCC_PID
|
||||
}
|
||||
|
||||
# we need to catch gocc server, so no init
|
||||
# setup() {
|
||||
# goc init
|
||||
# }
|
||||
|
||||
@test "test basic goc register command" {
|
||||
wait_profile_backend "register1"
|
||||
wait_profile_backend "register1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc register --center=http://127.0.0.1:60001 --name=xyz --address=http://137.0.0.1:666 --debug --debugcisyncfile ci-sync.bak;
|
||||
info register output: $output
|
||||
info register1 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"success"* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
||||
@test "test goc register without port" {
|
||||
wait_profile_backend "register2"
|
||||
wait_profile_backend "register2" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc register --center=http://127.0.0.1:60001 --name=xyz --address=http://137.0.0.1 --debug --debugcisyncfile ci-sync.bak;
|
||||
info register output: $output
|
||||
info register2 output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"missing port"* ]]
|
||||
}
|
||||
|
||||
wait $profile_pid
|
||||
}
|
||||
|
@ -34,10 +34,14 @@ teardown_file() {
|
||||
export GOPATH=$PWD/samples/simple_gopath_project
|
||||
export GO111MODULE=off
|
||||
cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project
|
||||
wait_profile_backend "run1"
|
||||
|
||||
wait_profile_backend "run1" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc run . --debug --debugcisyncfile ci-sync.bak;
|
||||
info run output: $output
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"hello, world."* ]]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
@ -22,7 +22,8 @@ wait_profile() {
|
||||
local timeout=10
|
||||
until [[ ${n} -ge ${timeout} ]]
|
||||
do
|
||||
# check whether the target port is listened by specific process
|
||||
LS=`ls`
|
||||
info $1, $LS
|
||||
if [[ -f ci-sync.bak ]]; then
|
||||
break
|
||||
fi
|
||||
@ -31,9 +32,10 @@ wait_profile() {
|
||||
done
|
||||
# collect from center
|
||||
goc profile -o filtered-$1.cov
|
||||
info "done $1 collect"
|
||||
}
|
||||
|
||||
wait_profile_backend() {
|
||||
rm ci-sync.bak || true
|
||||
coproc { wait_profile $1; }
|
||||
wait_profile $1
|
||||
}
|
@ -35,8 +35,11 @@ teardown_file() {
|
||||
}
|
||||
|
||||
@test "test basic goc version command" {
|
||||
wait_profile_backend "version"
|
||||
wait_profile_backend "version" &
|
||||
profile_pid=$!
|
||||
|
||||
run gocc version --debug --debugcisyncfile ci-sync.bak;
|
||||
[ "$output" = "(devel)" ]
|
||||
|
||||
wait $profile_pid
|
||||
}
|
Loading…
Reference in New Issue
Block a user