nksazonov / cake-factory

0 stars 0 forks source link

panic: http: multiple registrations for /metrics #1

Closed dnfd closed 3 years ago

dnfd commented 3 years ago
➜  cake-factory git:(main) ✗ go test ./... -cover -race
panic: http: multiple registrations for /metrics

goroutine 39 [running]:
net/http.(*ServeMux).Handle(0x10575a0, 0xc64010, 0x8, 0xd241e0, 0xc00007e6f0)
    /usr/lib/go/src/net/http/server.go:2444 +0x465
net/http.Handle(...)
    /usr/lib/go/src/net/http/server.go:2487
api/cake-api.startProm()
    /home/den/hackademy/cake-factory/cake-api/prometheus.go:29 +0xa8
created by api/cake-api.newRouter
    /home/den/hackademy/cake-factory/cake-api/main.go:44 +0x166
FAIL    api/cake-api    0.026s
?       api/jwt [no test files]
?       api/ws  [no test files]
FAIL
dnfd commented 3 years ago

Unit tests should not have external dependencies, like amqp connection and run with simple go test command.

dnfd commented 3 years ago
    for {
        body := <-send

Replace with for body := range send

nksazonov commented 3 years ago

Test crash fixed in 77b3810afd58cbeb125f24d707d0ce77a21309b2, for chan loop refactored in b2711ac5eb2b42e3110577a75daeeecb52425ea0