From b8a6cfc4b41b9b3d573ab672929bbdbede4d95f7 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Wed, 24 Jan 2024 10:38:01 -0800 Subject: [PATCH] stable order of the paths array --- lambda/invoke_loop.go | 13 +++++++------ lambda/invoke_loop_test.go | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lambda/invoke_loop.go b/lambda/invoke_loop.go index ab39147e..338237ea 100644 --- a/lambda/invoke_loop.go +++ b/lambda/invoke_loop.go @@ -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, diff --git a/lambda/invoke_loop_test.go b/lambda/invoke_loop_test.go index 0ce0db0c..3374dc2a 100644 --- a/lambda/invoke_loop_test.go +++ b/lambda/invoke_loop_test.go @@ -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{ @@ -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))