Skip to content

Commit 927339f

Browse files
Adds integration testing for application config
1 parent aa11483 commit 927339f

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

Makefile

+14-8
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,25 @@ test: build
5757
mkdir -p "$(TEST_DIR_DATA)" "$(TEST_DIR_LOGS)"
5858
$(GO) build -o bin/app test/app/app.go
5959
$(GO) build -o bin/cli test/cli/cli.go
60+
cp test/test-apps.config.json "$(TEST_DIR_DATA).."
61+
cp bin/app "$(TEST_DIR_DATA).."
6062
$(TEST_VARS) ./bin/pmond > test.log 2>&1 &
6163
sleep 3
62-
$(TEST_VARS) ./bin/cli exec $(ROOTDIR)/bin/app '{"name": "test-server"}'
63-
$(TEST_VARS) ./bin/cli ls_assert 1 running
64-
$(TEST_VARS) ./bin/cli exec $(ROOTDIR)/bin/app '{"name": "test-server2"}'
65-
$(TEST_VARS) ./bin/cli ls_assert 2 running
66-
$(TEST_VARS) ./bin/cli desc 2
64+
$(TEST_VARS) ./bin/cli exec $(ROOTDIR)/bin/app '{"name": "test-server3"}'
65+
$(TEST_VARS) ./bin/cli ls_assert 3 running
66+
$(TEST_VARS) ./bin/cli exec $(ROOTDIR)/bin/app '{"name": "test-server4"}'
67+
$(TEST_VARS) ./bin/cli ls_assert 4 running
68+
$(TEST_VARS) ./bin/cli desc 4
6769
$(TEST_VARS) ./bin/cli del 1
68-
$(TEST_VARS) ./bin/cli ls_assert 1 running
70+
$(TEST_VARS) ./bin/cli ls_assert 3 running
6971
$(TEST_VARS) ./bin/cli kill
70-
$(TEST_VARS) ./bin/cli ls_assert 1 stopped
72+
$(TEST_VARS) ./bin/cli ls_assert 3 stopped
7173
$(TEST_VARS) ./bin/cli init
72-
$(TEST_VARS) ./bin/cli ls_assert 1 running
74+
$(TEST_VARS) ./bin/cli ls_assert 3 running
75+
$(TEST_VARS) ./bin/cli drop
76+
$(TEST_VARS) ./bin/cli ls_assert 0
77+
$(TEST_VARS) ./bin/cli init
78+
$(TEST_VARS) ./bin/cli ls_assert 2 running
7379
$(TEST_VARS) ./bin/cli drop
7480
$(TEST_VARS) ./bin/cli ls_assert 0
7581
pidof pmond | xargs kill -9

test/cli/cli.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ func main() {
2121

2222
base.OpenSender()
2323

24-
args := os.Args
24+
execCmd(os.Args, 0)
25+
}
2526

27+
func execCmd(args []string, retries int) {
2628
cmdArg := args[1]
2729
if cmdArg == "ls_assert" {
2830
base.SendCmd("list", "")
@@ -39,8 +41,6 @@ func main() {
3941
panic("must provide a command")
4042
}
4143

42-
//time.Sleep(0 * time.Second)
43-
4444
newCmdResp := base.GetResponse()
4545
if len(newCmdResp.GetError()) > 0 {
4646
cli.Log.Fatal(newCmdResp.GetError())
@@ -61,7 +61,14 @@ func main() {
6161
pStatus := args[3]
6262
for _, p := range processList {
6363
if p.Status != pStatus {
64-
cli.Log.Fatalf("Expected process status of %d but got %d", expectedProcessLen, actualProcessLen)
64+
if retries < 3 { //three retries are allowed
65+
cli.Log.Infof("Expected process status of %s but got %s", pStatus, p.Status)
66+
cli.Log.Warnf("retry count: %d", retries+1)
67+
time.Sleep(time.Second * 5)
68+
execCmd(args, retries+1)
69+
} else {
70+
cli.Log.Fatalf("Expected process status of %s but got %s", pStatus, p.Status)
71+
}
6572
}
6673
}
6774
}

test/test-apps.config.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"apps": [
3+
{
4+
"file": "/usr/src/pmon3/app",
5+
"flags": {
6+
"name": "test-server-1"
7+
}
8+
},
9+
{
10+
"file": "/usr/src/pmon3/app",
11+
"flags": {
12+
"name": "test-server-2"
13+
}
14+
}
15+
]
16+
}

test/test-config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ posix_mq_user: null
2525
# specify a custom group to access files in posix_mq_dir (must also provide a user)
2626
posix_mq_group: null
2727
# a JSON configuration file to specify a list of apps to start on the first initialization
28-
apps_config_file:
28+
apps_config_file: /usr/src/pmon3/test-apps.config.json

0 commit comments

Comments
 (0)