Пример #1
0
func handleMessages() {
	for {
		if message, err := queue.Get(5e9); err == nil {
			go handle(message)
		} else {
			log.Printf("Failed to receive message: %s. Trying again...", err)
			continue
		}
	}
}
Пример #2
0
func (s *S) SetUpTest(c *C) {
	var (
		err error
		msg *queue.Message
	)
	for err == nil {
		if msg, err = queue.Get(1e6); err == nil {
			err = queue.Delete(msg)
		}
	}
}
Пример #3
0
// TODO(fss): simplify this test. Right now, it's a little monster.
func (s *S) TestCreateApp(c *C) {
	patchRandomReader()
	defer unpatchRandomReader()
	h := testHandler{}
	ts := s.t.StartGandalfTestServer(&h)
	defer ts.Close()
	a := App{
		Name:      "appname",
		Framework: "django",
		Units:     []Unit{{Machine: 3}},
	}
	expectedHost := "localhost"
	config.Set("host", expectedHost)

	err := CreateApp(&a, 3)
	c.Assert(err, IsNil)
	defer a.Destroy()
	c.Assert(a.State, Equals, "pending")
	var retrievedApp App
	err = db.Session.Apps().Find(bson.M{"name": a.Name}).One(&retrievedApp)
	c.Assert(err, IsNil)
	c.Assert(retrievedApp.Name, Equals, a.Name)
	c.Assert(retrievedApp.Framework, Equals, a.Framework)
	c.Assert(retrievedApp.State, Equals, a.State)
	env := a.InstanceEnv(s3InstanceName)
	c.Assert(env["TSURU_S3_ENDPOINT"].Value, Equals, s.t.S3Server.URL())
	c.Assert(env["TSURU_S3_ENDPOINT"].Public, Equals, false)
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Value, Equals, "true")
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Public, Equals, false)
	e, ok := env["TSURU_S3_ACCESS_KEY_ID"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	e, ok = env["TSURU_S3_SECRET_KEY"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	c.Assert(env["TSURU_S3_BUCKET"].Value, HasLen, maxBucketSize)
	c.Assert(env["TSURU_S3_BUCKET"].Value, Equals, "appnamee3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3")
	c.Assert(env["TSURU_S3_BUCKET"].Public, Equals, false)
	env = a.InstanceEnv("")
	c.Assert(env["APPNAME"].Value, Equals, a.Name)
	c.Assert(env["APPNAME"].Public, Equals, false)
	c.Assert(env["TSURU_HOST"].Value, Equals, expectedHost)
	c.Assert(env["TSURU_HOST"].Public, Equals, false)
	expectedMessage := queue.Message{
		Action: RegenerateApprc,
		Args:   []string{a.Name},
	}
	message, err := queue.Get(1e6)
	c.Assert(err, IsNil)
	defer queue.Delete(message)
	c.Assert(message.Action, Equals, expectedMessage.Action)
	c.Assert(message.Args, DeepEquals, expectedMessage.Args)
	c.Assert(s.provisioner.GetUnits(&a), HasLen, 3)
}
Пример #4
0
func (s *S) TestCreateBucketForward(c *C) {
	patchRandomReader()
	defer unpatchRandomReader()
	a := App{
		Name:      "appname",
		Framework: "django",
		Units:     []Unit{{Machine: 3}},
	}
	expectedHost := "localhost"
	config.Set("host", expectedHost)
	insert := new(insertApp)
	err := insert.forward(&a)
	c.Assert(err, IsNil)
	defer insert.backward(&a)
	bucket := new(createBucketIam)
	err = bucket.forward(&a)
	c.Assert(err, IsNil)
	defer bucket.backward(&a)
	err = a.Get()
	c.Assert(err, IsNil)
	env := a.InstanceEnv(s3InstanceName)
	c.Assert(env["TSURU_S3_ENDPOINT"].Value, Equals, s.t.S3Server.URL())
	c.Assert(env["TSURU_S3_ENDPOINT"].Public, Equals, false)
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Value, Equals, "true")
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Public, Equals, false)
	e, ok := env["TSURU_S3_ACCESS_KEY_ID"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	e, ok = env["TSURU_S3_SECRET_KEY"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	c.Assert(env["TSURU_S3_BUCKET"].Value, HasLen, maxBucketSize)
	c.Assert(env["TSURU_S3_BUCKET"].Value, Equals, "appnamee3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3")
	c.Assert(env["TSURU_S3_BUCKET"].Public, Equals, false)
	env = a.InstanceEnv("")
	c.Assert(env["APPNAME"].Value, Equals, a.Name)
	c.Assert(env["APPNAME"].Public, Equals, false)
	c.Assert(env["TSURU_HOST"].Value, Equals, expectedHost)
	c.Assert(env["TSURU_HOST"].Public, Equals, false)
	expected := queue.Message{
		Action: RegenerateApprc,
		Args:   []string{a.Name},
	}
	message, err := queue.Get(2e9)
	c.Assert(err, IsNil)
	defer queue.Delete(message)
	c.Assert(message.Action, Equals, expected.Action)
	c.Assert(message.Args, DeepEquals, expected.Args)
}
Пример #5
0
func (s *S) TestAddUnits(c *C) {
	app := App{Name: "warpaint", Framework: "python"}
	err := db.Session.Apps().Insert(app)
	c.Assert(err, IsNil)
	defer db.Session.Apps().Remove(bson.M{"name": app.Name})
	s.provisioner.Provision(&app)
	defer s.provisioner.Destroy(&app)
	err = app.AddUnits(5)
	c.Assert(err, IsNil)
	units := s.provisioner.GetUnits(&app)
	c.Assert(units, HasLen, 6)
	err = app.AddUnits(2)
	c.Assert(err, IsNil)
	units = s.provisioner.GetUnits(&app)
	c.Assert(units, HasLen, 8)
	for _, unit := range units {
		c.Assert(unit.AppName, Equals, app.Name)
	}
	err = app.Get()
	c.Assert(err, IsNil)
	c.Assert(app.Units, HasLen, 7)
	var expectedMessages MessageList
	names := make([]string, len(app.Units))
	for i, unit := range app.Units {
		names[i] = unit.Name
		expected := fmt.Sprintf("%s/%d", app.Name, i+1)
		c.Assert(unit.Name, Equals, expected)
		messages := []queue.Message{
			{Action: RegenerateApprc, Args: []string{app.Name, unit.Name}},
			{Action: StartApp, Args: []string{app.Name, unit.Name}},
		}
		expectedMessages = append(expectedMessages, messages...)
	}
	gotMessages := make(MessageList, expectedMessages.Len())
	for i := range expectedMessages {
		message, err := queue.Get(1e6)
		c.Assert(err, IsNil)
		defer queue.Delete(message)
		gotMessages[i] = queue.Message{
			Action: message.Action,
			Args:   message.Args,
		}
	}
	sort.Sort(expectedMessages)
	sort.Sort(gotMessages)
	c.Assert(gotMessages, DeepEquals, expectedMessages)
}