Beispiel #1
0
func BenchmarkPushKey(b *testing.B) {
	queueName := "test_crawler"
	cfg, err := config.Get("/etc/yascrapy/core.json")
	if err != nil {
		b.Error(err.Error())
	}
	conn, err := rabbitmq.GetConn(cfg)
	if err != nil {
		b.Error(err.Error())
	}
	err = rabbitmq.DeclareQueue(conn, queueName)
	if err != nil {
		b.Error(err.Error())
	}
	ch, err := rabbitmq.MakeChannel(conn)
	defer ch.Close()
	if err != nil {
		b.Error("TestPush fail", err.Error())
	}
	for i := 0; i < b.N; i++ {
		req := initRequest()
		req.Url = fmt.Sprintf("%s%d", req.Url, i)
		resp := initResponse(req)
		err = PushKey(ch, resp, queueName)
		if err != nil {
			b.Log(err.Error())
		}
	}
}
Beispiel #2
0
func TestPushKey(t *testing.T) {
	queueName := "test_crawler"
	req := initRequest()
	r := initResponse(req)
	cfg, err := config.Get("/etc/yascrapy/core.json")
	if err != nil {
		t.Error(err.Error())
	}
	conn, err := rabbitmq.GetConn(cfg)
	if err != nil {
		t.Error(err.Error())
	}
	err = rabbitmq.DeclareQueue(conn, queueName)
	if err != nil {
		t.Error(err.Error())
	}
	ch, err := rabbitmq.MakeChannel(conn)
	defer ch.Close()
	if err != nil {
		t.Error("TestPushKey fail %s", err.Error())
	}
	err = PushKey(ch, r, queueName)
	if err != nil {
		t.Error("TestPushKey fail ", err.Error())
	} else {
		t.Log("TestPushKey ok")
	}
}