Skip to content

Commit f45d433

Browse files
committed
test(git_push): add concurrent push specs
1 parent 19755ef commit f45d433

2 files changed

Lines changed: 113 additions & 9 deletions

File tree

tests/cmd/git/commands.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ const (
2323
pushCommandLineString = "GIT_SSH=%s GIT_KEY=%s git push deis master"
2424
)
2525

26+
// StartPush starts a `git push deis master` command and returns the command session.
27+
func StartPush(user model.User, keyPath string) *Session {
28+
sess, err := cmd.Start(pushCommandLineString, &user, settings.GitSSH, keyPath)
29+
Expect(err).NotTo(HaveOccurred())
30+
return sess
31+
}
32+
2633
// Push executes a `git push deis master` from the current directory using the provided key.
2734
func Push(user model.User, keyPath string, app model.App, banner string) {
28-
sess := doGitPush(user, keyPath)
35+
sess := StartPush(user, keyPath)
2936
// sess.Wait(settings.MaxEventuallyTimeout)
3037
// output := string(sess.Out.Contents())
3138
// Expect(output).To(MatchRegexp(`Done, %s:v\d deployed to Deis`, app.Name))
3239
Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
40+
Curl(app, banner)
41+
}
42+
43+
// Curl polls an app over HTTP until it returns the expected "Powered by" banner.
44+
func Curl(app model.App, banner string) {
3345
// curl the app's root URL and print just the HTTP response code
3446
cmdRetryTimeout := 60
3547
curlCmd := model.Cmd{CommandLineString: fmt.Sprintf(
@@ -43,12 +55,12 @@ func Push(user model.User, keyPath string, app model.App, banner string) {
4355
// PushWithInterrupt executes a `git push deis master` from the current
4456
// directory using the provided key, but then halts the progress via SIGINT.
4557
func PushWithInterrupt(user model.User, keyPath string) {
46-
sess := doGitPush(user, keyPath)
58+
sess := StartPush(user, keyPath)
4759
Eventually(sess.Err).Should(Say("Starting build... but first, coffee!"))
4860

4961
sess = sess.Interrupt()
5062

51-
newSess := doGitPush(user, keyPath)
63+
newSess := StartPush(user, keyPath)
5264
Eventually(newSess.Err).ShouldNot(Say("exec request failed on channel 0"))
5365
Eventually(newSess.Err).Should(Say("fatal: remote error: Another git push is ongoing"))
5466
Eventually(newSess, settings.DefaultEventuallyTimeout).Should(Exit(128))
@@ -66,9 +78,3 @@ func PushUntilResult(user model.User, keyPath string, expectedCmdResult model.Cm
6678
Eventually(cmd.RetryUntilResult(pushCmd, expectedCmdResult, 5*time.Second,
6779
settings.MaxEventuallyTimeout)).Should(BeTrue())
6880
}
69-
70-
func doGitPush(user model.User, keyPath string) *Session {
71-
sess, err := cmd.Start(pushCommandLineString, &user, settings.GitSSH, keyPath)
72-
Expect(err).NotTo(HaveOccurred())
73-
return sess
74-
}

tests/git_push_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ package tests
22

33
import (
44
"os"
5+
"time"
56

67
"github.com/deis/workflow-e2e/tests/cmd"
78
"github.com/deis/workflow-e2e/tests/cmd/apps"
89
"github.com/deis/workflow-e2e/tests/cmd/auth"
910
"github.com/deis/workflow-e2e/tests/cmd/git"
1011
"github.com/deis/workflow-e2e/tests/cmd/keys"
1112
"github.com/deis/workflow-e2e/tests/model"
13+
"github.com/deis/workflow-e2e/tests/settings"
1214

1315
. "github.com/onsi/ginkgo"
1416
. "github.com/onsi/gomega"
17+
. "github.com/onsi/gomega/gbytes"
18+
. "github.com/onsi/gomega/gexec"
1519
)
1620

1721
var _ = Describe("git push deis master", func() {
@@ -70,6 +74,53 @@ var _ = Describe("git push deis master", func() {
7074
})
7175
})
7276

77+
Specify("that user can deploy that app only once concurrently", func() {
78+
sess := git.StartPush(user, keyPath)
79+
// sleep for five seconds, then push the same app
80+
time.Sleep(5000 * time.Millisecond)
81+
sess2 := git.StartPush(user, keyPath)
82+
Eventually(sess2.Err).Should(Say("fatal: remote error: Another git push is ongoing"))
83+
Eventually(sess2).Should(Exit(128))
84+
// TODO: loop until success
85+
Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
86+
})
87+
88+
Context("and who has another local git repo containing buildpack source code", func() {
89+
90+
BeforeEach(func() {
91+
os.Chdir("..")
92+
output, err := cmd.Execute(`git clone https://github.com/deis/example-nodejs-express.git`)
93+
Expect(err).NotTo(HaveOccurred(), output)
94+
})
95+
96+
Context("and has run `deis apps:create` from within that repo", func() {
97+
98+
var app2 model.App
99+
100+
BeforeEach(func() {
101+
os.Chdir("example-nodejs-express")
102+
app2 = apps.Create(user)
103+
})
104+
105+
AfterEach(func() {
106+
apps.Destroy(user, app2)
107+
})
108+
109+
Specify("that user can deploy both apps concurrently", func() {
110+
os.Chdir("../example-go")
111+
sess := git.StartPush(user, keyPath)
112+
os.Chdir("../example-nodejs-express")
113+
sess2 := git.StartPush(user, keyPath)
114+
Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
115+
Eventually(sess2, settings.MaxEventuallyTimeout).Should(Exit(0))
116+
git.Curl(app, "Powered by Deis")
117+
git.Curl(app2, "Powered by Deis")
118+
})
119+
120+
})
121+
122+
})
123+
73124
})
74125

75126
})
@@ -98,6 +149,53 @@ var _ = Describe("git push deis master", func() {
98149
git.Push(user, keyPath, app, "Powered by Deis")
99150
})
100151

152+
Specify("that user can deploy that app only once concurrently", func() {
153+
sess := git.StartPush(user, keyPath)
154+
// sleep for five seconds, then push the same app
155+
time.Sleep(5000 * time.Millisecond)
156+
sess2 := git.StartPush(user, keyPath)
157+
Eventually(sess2.Err).Should(Say("fatal: remote error: Another git push is ongoing"))
158+
Eventually(sess2).Should(Exit(128))
159+
// TODO: loop until success
160+
Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
161+
})
162+
163+
Context("and who has another local git repo containing dockerfile source code", func() {
164+
165+
BeforeEach(func() {
166+
os.Chdir("..")
167+
output, err := cmd.Execute(`git clone https://github.com/deis/example-dockerfile-python.git`)
168+
Expect(err).NotTo(HaveOccurred(), output)
169+
})
170+
171+
Context("and has run `deis apps:create` from within that repo", func() {
172+
173+
var app2 model.App
174+
175+
BeforeEach(func() {
176+
os.Chdir("example-dockerfile-python")
177+
app2 = apps.Create(user)
178+
})
179+
180+
AfterEach(func() {
181+
apps.Destroy(user, app2)
182+
})
183+
184+
Specify("that user can deploy both apps concurrently", func() {
185+
os.Chdir("../example-dockerfile-http")
186+
sess := git.StartPush(user, keyPath)
187+
os.Chdir("../example-dockerfile-python")
188+
sess2 := git.StartPush(user, keyPath)
189+
Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
190+
Eventually(sess2, settings.MaxEventuallyTimeout).Should(Exit(0))
191+
git.Curl(app, "Powered by Deis")
192+
git.Curl(app2, "Powered by Deis")
193+
})
194+
195+
})
196+
197+
})
198+
101199
})
102200

103201
})

0 commit comments

Comments
 (0)