MCPcopy Index your code
hub / github.com/coder/coder / TestProvision_TextFileBusy

Function TestProvision_TextFileBusy

provisioner/terraform/provision_test.go:327–389  ·  view source on GitHub ↗

below we exec fake_text_file_busy.sh, which causes the kernel to execute it, and if more than one process tries to do this, it can cause "text file busy" to be returned to us. In this test we want to simulate "text file busy" getting logged by terraform, due to an issue with the terraform-provider-c

(t *testing.T)

Source from the content-addressed store, hash-verified

325// terraform-provider-coder
326// nolint: paralleltest
327func TestProvision_TextFileBusy(t *testing.T) {
328 cwd, err := os.Getwd()
329 require.NoError(t, err)
330 fakeBin := filepath.Join(cwd, "testdata", "fake_text_file_busy.sh")
331
332 dir := t.TempDir()
333 binPath := filepath.Join(dir, "terraform")
334
335 // Example: exec /path/to/terraform_fake_cancel.sh 1.2.1 apply "$@"
336 content := fmt.Sprintf("#!/bin/sh\nexec %q %s \"$@\"\n", fakeBin, terraform.TerraformVersion.String())
337 err = os.WriteFile(binPath, []byte(content), 0o755) //#nosec
338 require.NoError(t, err)
339
340 workDir := t.TempDir()
341
342 err = os.Mkdir(filepath.Join(workDir, ".coder"), 0o700)
343 require.NoError(t, err)
344 l, err := net.Listen("unix", filepath.Join(workDir, ".coder", "pprof"))
345 require.NoError(t, err)
346 defer l.Close()
347 handlerCalled := 0
348 // nolint: gosec
349 srv := &http.Server{
350 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
351 assert.Equal(t, "/debug/pprof/goroutine", r.URL.Path)
352 w.WriteHeader(http.StatusOK)
353 _, err := w.Write([]byte("thestacks\n"))
354 assert.NoError(t, err)
355 handlerCalled++
356 }),
357 }
358 srvErr := make(chan error, 1)
359 go func() {
360 srvErr <- srv.Serve(l)
361 }()
362
363 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
364 ctx, api := setupProvisioner(t, &provisionerServeOptions{
365 binaryPath: binPath,
366 exitTimeout: time.Second,
367 workDir: workDir,
368 logger: &logger,
369 })
370
371 sess := configure(ctx, t, api, &proto.Config{})
372
373 err = sendInit(sess, testutil.CreateTar(t, nil))
374 require.NoError(t, err)
375
376 found := false
377 for {
378 msg, err := sess.Recv()
379 require.NoError(t, err)
380
381 if c := msg.GetInit(); c != nil {
382 require.Contains(t, c.Error, "exit status 1")
383 found = true
384 break

Callers

nothing calls this directly

Calls 15

ServeMethod · 0.95
CreateTarFunction · 0.92
setupProvisionerFunction · 0.85
configureFunction · 0.85
sendInitFunction · 0.85
TempDirMethod · 0.65
WriteFileMethod · 0.65
ListenMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65
RecvMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected