Skip to content

Commit 01d8000

Browse files
committed
Apply pull request review suggestions
1 parent 792410f commit 01d8000

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

js/modules/k6/data/data.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,18 @@ func (d *Data) NewSharedArrayFrom(rt *sobek.Runtime, name string, r RecordReader
136136
arr = append(arr, string(marshaled))
137137
}
138138

139-
d.shared.mu.Lock()
140-
defer d.shared.mu.Unlock()
139+
return d.shared.set(name, arr).Wrap(rt).ToObject(rt)
140+
}
141+
142+
// set is a helper method to set a shared array in the underlying shared arrays map.
143+
func (s *sharedArrays) set(name string, arr []string) sharedArray {
144+
// FIXME (@oleiade): we should probably return an error if the name is empty?
145+
s.mu.Lock()
146+
defer s.mu.Unlock()
141147
array := sharedArray{arr: arr}
142-
d.shared.data[name] = array
148+
s.data[name] = array
143149

144-
return array.Wrap(rt).ToObject(rt)
150+
return array
145151
}
146152

147153
func (s *sharedArrays) get(rt *sobek.Runtime, name string, call sobek.Callable) sharedArray {

js/modules/k6/experimental/csv/module.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ type (
2727
// RootModule is the global module instance that will create instances of our
2828
// module for each VU.
2929
RootModule struct {
30-
// FIXME: we end up instantiating the data module ourselves, which would live side by side with other
31-
// usages of the data module. This works, but might not be ideal. Is there a way for us to import the module
32-
// in a way that we reuse a global test scope's data module instance?
3330
dataModuleInstance *data.Data
3431
}
3532

@@ -78,7 +75,8 @@ func (mi *ModuleInstance) Exports() modules.Exports {
7875

7976
// Parser is a CSV parser.
8077
type Parser struct {
81-
CurrentLine atomic.Int64
78+
// currentLine holds the current line number being read by the parser.
79+
currentLine atomic.Int64
8280

8381
// reader is the CSV reader that enables to read records from the provided
8482
// input file.
@@ -104,7 +102,7 @@ func (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) *sobek.Pr
104102
// 1. Make sure the Sobek object is a fs.File (sobek operation)
105103
var fileObj fs.File
106104
if err := mi.vu.Runtime().ExportTo(file, &fileObj); err != nil {
107-
reject(fmt.Errorf("first arg doesn't appear to be a *file.File instance, it's %T", file))
105+
reject(fmt.Errorf("first argument expected to be a fs.File instance, got %T instead", file))
108106
return promise
109107
}
110108

@@ -113,7 +111,7 @@ func (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) *sobek.Pr
113111
var err error
114112
parserOptions, err = newParserOptionsFrom(options.ToObject(rt))
115113
if err != nil {
116-
reject(fmt.Errorf("encountered an error while interpreting Parser options; reason: %w", err))
114+
reject(fmt.Errorf("failed to interpret the provided Parser options; reason: %w", err))
117115
return promise
118116
}
119117
}
@@ -147,13 +145,16 @@ func (mi *ModuleInstance) NewParser(call sobek.ConstructorCall) *sobek.Object {
147145
}
148146

149147
if len(call.Arguments) < 1 || sobek.IsUndefined(call.Argument(0)) {
150-
common.Throw(rt, fmt.Errorf("parser constructor takes at least one non-nil source argument"))
148+
common.Throw(rt, fmt.Errorf("csv Parser constructor takes at least one non-nil source argument"))
151149
}
152150

153-
// 1. Make sure the Sobek object is a fs.File (sobek operation)
151+
// 1. Make sure the Sobek object is a fs.File (Sobek operation)
154152
var file fs.File
155153
if err := mi.vu.Runtime().ExportTo(call.Argument(0), &file); err != nil {
156-
common.Throw(mi.vu.Runtime(), fmt.Errorf("first arg doesn't appear to be a *file.File instance"))
154+
common.Throw(
155+
mi.vu.Runtime(),
156+
fmt.Errorf("first argument expected to be a fs.File instance, got %T instead", call.Argument(0)),
157+
)
157158
}
158159

159160
options := newDefaultParserOptions()
@@ -200,7 +201,7 @@ func (p *Parser) Next() *sobek.Promise {
200201
}
201202
}
202203

203-
p.CurrentLine.Add(1)
204+
p.currentLine.Add(1)
204205

205206
resolve(parseResult{Done: done, Value: records})
206207
}()

0 commit comments

Comments
 (0)