Пример #1
0
func (self *Server) Start() {
	fmt.Printf("Connecting to database... ")
	session, err := mgo.Dial("localhost")

	utils.HandleError(err)

	fmt.Println("done.")

	self.listener, err = net.Listen("tcp", ":8945")
	utils.HandleError(err)

	database.Init(database.NewMongoSession(session.Copy()), "mud")
}
Пример #2
0
func (s *ModelSuite) SetUpSuite(c *C) {
	session, err := mgo.Dial("localhost")
	c.Assert(err, Equals, nil)

	if err != nil {
		return
	}

	dbName := "unit_model_test"

	_db = session.DB(dbName)

	session.DB(dbName).DropDatabase()

	database.Init(database.NewMongoSession(session), dbName)
}
Пример #3
0
func Test_ThreadSafety(t *testing.T) {
	runtime.GOMAXPROCS(2)
	database.Init(&TestSession{}, "unit_dbtest")

	char := database.NewPc("test", testutils.MockId(""), testutils.MockId(""))

	var wg sync.WaitGroup
	wg.Add(2)

	go func() {
		for i := 0; i < 100; i++ {
			char.SetName(strconv.Itoa(i))
		}
		wg.Done()
	}()

	go func() {
		for i := 0; i < 100; i++ {
		}
		wg.Done()
	}()

	wg.Wait()
}