Skip to content

Commit

Permalink
stable order of the paths array
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoffatt committed Jan 24, 2024
1 parent 9f77144 commit b8a6cfc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lambda/invoke_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ type xrayError struct {
}

func makeXRayError(invokeResponseError *messages.InvokeResponse_Error) *xrayError {
pathSet := make(map[string]struct{}, len(invokeResponseError.StackTrace))
paths := make([]string, 0, len(invokeResponseError.StackTrace))
visitedPaths := make(map[string]struct{}, len(invokeResponseError.StackTrace))
for _, frame := range invokeResponseError.StackTrace {
pathSet[frame.Path] = struct{}{}
}
paths := make([]string, 0, len(pathSet))
for path := range pathSet {
paths = append(paths, path)
if _, exists := visitedPaths[frame.Path]; !exists {
visitedPaths[frame.Path] = struct{}{}
paths = append(paths, frame.Path)
}
}

cwd, _ := os.Getwd()
exceptions := []xrayException{{
Type: invokeResponseError.Type,
Expand Down
38 changes: 37 additions & 1 deletion lambda/invoke_loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,25 @@ func TestXRayCausePlumbing(t *testing.T) {
{Label: "hi", Path: "hello/hello", Line: 12},
},
},
messages.InvokeResponse_Error{
Type: "yoloError",
Message: "hello yolo",
StackTrace: []*messages.InvokeResponse_Error_StackFrame{
{Label: "hi", Path: "hello/hello", Line: 12},
{Label: "hihi", Path: "hello/hello", Line: 13},
{Label: "yolo", Path: "yolo", Line: 2},
{Label: "hi", Path: "hello/hello", Line: 14},
},
},
messages.InvokeResponse_Error{
Type: "yoloError",
Message: "hello yolo",
StackTrace: []*messages.InvokeResponse_Error_StackFrame{},
},
messages.InvokeResponse_Error{
Type: "yoloError",
Message: "hello yolo",
},
}
wd, _ := os.Getwd()
expected := []string{
Expand All @@ -132,14 +146,36 @@ func TestXRayCausePlumbing(t *testing.T) {
}`,
`{
"working_directory":"` + wd + `",
"paths": [],
"paths": ["hello/hello", "yolo"],
"exceptions": [{
"type": "yoloError",
"message": "hello yolo",
"stack": [
{"label": "hi", "path": "hello/hello", "line": 12},
{"label": "hihi", "path": "hello/hello", "line": 13},
{"label": "yolo", "path": "yolo", "line": 2},
{"label": "hi", "path": "hello/hello", "line": 14}
]
}]
}`,
`{
"working_directory":"` + wd + `",
"paths": [],
"exceptions": [{
"type": "yoloError",
"message": "hello yolo",
"stack": []
}]
}`,
`{
"working_directory":"` + wd + `",
"paths": [],
"exceptions": [{
"type": "yoloError",
"message": "hello yolo",
"stack": []
}]
}`,
}
require.Equal(t, len(errors), len(expected))
ts, record := runtimeAPIServer(``, len(errors))
Expand Down

0 comments on commit b8a6cfc

Please sign in to comment.