Skip to content

Commit

Permalink
Fix the HAR converter to work with HAR files that don't have pages (#806
Browse files Browse the repository at this point in the history
)

This is a hacky and hopefully temporary fix so we can close #793
  • Loading branch information
na-- authored Oct 12, 2018
1 parent bb6e975 commit 5e6a380
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion converter/har/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ func Convert(h HAR, options lib.Options, minSleep, maxSleep uint, enableChecks b
pages := h.Log.Pages
sort.Sort(PageByStarted(pages))

// Hack to handle HAR files without a pages array
// Temporary fix for https://github.com/loadimpact/k6/issues/793
if len(pages) == 0 {
pages = []Page{{
ID: "", // The Pageref property of all Entries will be an empty string
Title: "Global",
Comment: "Placeholder page since there were no pages specified in the HAR file",
}}
}

// Grouping by page and URL filtering
pageEntries := make(map[string][]*Entry)
for _, e := range h.Log.Entries {
Expand Down Expand Up @@ -133,7 +143,14 @@ func Convert(h HAR, options lib.Options, minSleep, maxSleep uint, enableChecks b
for i, page := range pages {

entries := pageEntries[page.ID]
fprintf(w, "\tgroup(%q, function() {\n", page.ID+" - "+page.Title)

scriptGroupName := page.ID + " - " + page.Title
if page.ID == "" {
// Temporary fix for https://github.com/loadimpact/k6/issues/793
// I can't just remove the group() call since all of the subsequent code indentation is hardcoded...
scriptGroupName = page.Title
}
fprintf(w, "\tgroup(%q, function() {\n", scriptGroupName)

sort.Sort(EntryByStarted(entries))

Expand Down
3 changes: 2 additions & 1 deletion release notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ Thanks to @AndriiChuzhynov for implementing this! (#766)
* HTTP: Correct metric tracking when HTTP requests are redirected (#753)
* HAR converter: Added escaping for page IDs and names in the generated scripts (#801)
* Setup data: Distinguish between `undefined` (when there is no `setup()` function or when it doesn't return anything) and `null` (when `setup()` explicitly returns `null`) values for the setup `data` that's passed to the default function and `teardown()` (#799)
* Setup data: Prevent data races by having each VU have its own independent copy of the setup data (#799)
* Setup data: Prevent data races by having each VU have its own independent copy of the setup data (#799)
* HAR converter: Support HAR files that don't have a `pages` array (#806)

0 comments on commit 5e6a380

Please sign in to comment.