MCPcopy Index your code
hub / github.com/klauspost/compress / TestEncoder_EncodeAllConcurrent

Function TestEncoder_EncodeAllConcurrent

zstd/encoder_test.go:108–161  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestEncoder_EncodeAllConcurrent(t *testing.T) {
109 in, err := os.ReadFile("testdata/z000028")
110 if err != nil {
111 t.Fatal(err)
112 }
113 in = append(in, in...)
114
115 // When running race no more than 8k goroutines allowed.
116 n := 400 / runtime.GOMAXPROCS(0)
117 if testing.Short() {
118 n = 20 / runtime.GOMAXPROCS(0)
119 }
120 dec, err := NewReader(nil)
121 if err != nil {
122 t.Fatal(err)
123 }
124 defer dec.Close()
125 for _, opts := range getEncOpts(2) {
126 t.Run(opts.name, func(t *testing.T) {
127 rng := rand.New(rand.NewSource(0x1337))
128 e, err := NewWriter(nil, opts.o...)
129 if err != nil {
130 t.Fatal(err)
131 }
132 defer e.Close()
133 var wg sync.WaitGroup
134 wg.Add(n)
135 for i := 0; i < n; i++ {
136 in := in[rng.Int()&1023:]
137 in = in[:rng.Intn(len(in))]
138 go func() {
139 defer wg.Done()
140 dst := e.EncodeAll(in, nil)
141 if len(dst) > e.MaxEncodedSize(len(in)) {
142 t.Errorf("max encoded size for %v: got: %d, want max: %d", len(in), len(dst), e.MaxEncodedSize(len(in)))
143 }
144 //t.Log("Simple Encoder len", len(in), "-> zstd len", len(dst))
145 decoded, err := dec.DecodeAll(dst, nil)
146 if err != nil {
147 t.Error(err, len(decoded))
148 }
149 if !bytes.Equal(decoded, in) {
150 //os.WriteFile("testdata/"+t.Name()+"-z000028.got", decoded, os.ModePerm)
151 //os.WriteFile("testdata/"+t.Name()+"-z000028.want", in, os.ModePerm)
152 t.Error("Decoded does not match")
153 return
154 }
155 }()
156 }
157 wg.Wait()
158 //t.Log("Encoded content matched.", n, "goroutines")
159 })
160 }
161}
162
163func TestEncoder_EncodeAllEncodeXML(t *testing.T) {
164 f, err := os.Open("testdata/xml.zst")

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
CloseMethod · 0.95
getEncOptsFunction · 0.85
FatalMethod · 0.80
EncodeAllMethod · 0.80
MaxEncodedSizeMethod · 0.80
DecodeAllMethod · 0.80
NewReaderFunction · 0.70
NewWriterFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…