chore: add http logging, improve e2e debug (#20406)
Co-authored-by: andig <andi@evcc.io>
This commit is contained in:
parent
e573b9546f
commit
bdd83d9d88
4 changed files with 39 additions and 4 deletions
|
|
@ -6,8 +6,8 @@ import { defineConfig, devices } from "@playwright/test";
|
|||
export default defineConfig({
|
||||
testDir: "./tests",
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 3 : 0,
|
||||
timeout: 30000, // default 30s
|
||||
retries: process.env.CI ? 4 : 0,
|
||||
timeout: 20000, // default 30s
|
||||
workers: process.env.CI ? 3 : 4,
|
||||
reporter: "html",
|
||||
use: {
|
||||
|
|
@ -19,7 +19,10 @@ export default defineConfig({
|
|||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
use: { ...devices["Desktop Chrome"], channel: "chrome" },
|
||||
use: {
|
||||
...devices["Desktop Chrome"],
|
||||
viewport: { width: 1400, height: 1400 },
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,10 +39,40 @@ type HTTPd struct {
|
|||
*http.Server
|
||||
}
|
||||
|
||||
// loggingResponseWriter wraps http.ResponseWriter to capture status code
|
||||
type loggingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func (lrw *loggingResponseWriter) WriteHeader(code int) {
|
||||
lrw.statusCode = code
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
// NewHTTPd creates HTTP server with configured routes for loadpoint
|
||||
func NewHTTPd(addr string, hub *SocketHub) *HTTPd {
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
|
||||
log := util.NewLogger("httpd")
|
||||
|
||||
// log all requests
|
||||
router.Use(func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// simple logging for websocket connections
|
||||
if r.Header.Get("Upgrade") == "websocket" {
|
||||
log.TRACE.Printf("%s %s", r.Method, r.URL.Path)
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// capture status code
|
||||
lrw := &loggingResponseWriter{ResponseWriter: w, statusCode: http.StatusOK}
|
||||
next.ServeHTTP(lrw, r)
|
||||
log.TRACE.Printf("%s %s %d", r.Method, r.URL.Path, lrw.statusCode)
|
||||
})
|
||||
})
|
||||
|
||||
// websocket
|
||||
router.HandleFunc("/ws", socketHandler(hub))
|
||||
|
||||
|
|
|
|||
|
|
@ -84,8 +84,9 @@ async function _start(config, flags = []) {
|
|||
// wait for port to be available
|
||||
await waitOn({ resources: [`tcp:${port}`], reverse: true, log: true });
|
||||
const additionalFlags = typeof flags === "string" ? [flags] : flags;
|
||||
additionalFlags.push("--log", "debug,httpd:trace");
|
||||
log("starting evcc", { config, port, additionalFlags });
|
||||
const instance = spawn(BINARY, ["--config", configFile, additionalFlags], {
|
||||
const instance = spawn(BINARY, ["--config", configFile, ...additionalFlags], {
|
||||
env: { EVCC_NETWORK_PORT: port.toString(), EVCC_DATABASE_DSN: dbPath() },
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ test.describe("basics", async () => {
|
|||
await expect(page.getByTestId("sessions-entry")).toHaveCount(0);
|
||||
});
|
||||
test("month with data", async ({ page }) => {
|
||||
await page.setViewportSize(desktop);
|
||||
await page.goto("/#/sessions?year=2023&month=5");
|
||||
await expect(page.getByTestId("navigate-month")).toHaveText("May");
|
||||
await expect(page.getByTestId("navigate-year")).toHaveText("2023");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue