...

Source file src/github.com/onsi/ginkgo/v2/integration/progress_test.go

Documentation: github.com/onsi/ginkgo/v2/integration

     1  package integration_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"regexp"
     8  	"strconv"
     9  	"syscall"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  	"github.com/onsi/gomega/gbytes"
    14  	"github.com/onsi/gomega/gexec"
    15  )
    16  
    17  var _ = Describe("Emitting progress", func() {
    18  	Describe("progress reports", func() {
    19  		BeforeEach(func() {
    20  			fm.MountFixture("progress_report")
    21  		})
    22  
    23  		It("emits progress when a singal is sent and when tests take too long", func() {
    24  			session := startGinkgo(fm.PathTo("progress_report"), "--poll-progress-after=1500ms", "--poll-progress-interval=200ms", "--no-color")
    25  			Eventually(session).Should(gbytes.Say(`READY `))
    26  			buf := make([]byte, 128)
    27  			_, err := session.Out.Read(buf)
    28  			Ω(err).ShouldNot(HaveOccurred())
    29  			pid, err := strconv.Atoi(regexp.MustCompile(`\d*`).FindString(string(buf)))
    30  			Ω(err).ShouldNot(HaveOccurred())
    31  
    32  			syscall.Kill(pid, syscall.SIGUSR1)
    33  			Eventually(session).Should(gbytes.Say(`can track on demand \(Spec Runtime:`))
    34  			Eventually(session).Should(gbytes.Say(`In \[It\] \(Node Runtime:`))
    35  			Eventually(session).Should(gbytes.Say(`\[By Step\] Step B \(Step Runtime:`))
    36  
    37  			Eventually(session).Should(gbytes.Say(`Begin Captured GinkgoWriter Output`))
    38  			Eventually(session).Should(gbytes.Say(`\.\.\.`))
    39  			for i := 3; i <= 12; i++ {
    40  				Eventually(session).Should(gbytes.Say(fmt.Sprintf("ginkgo-writer-output-%d", i)))
    41  			}
    42  
    43  			Eventually(session).Should(gbytes.Say(`|\s*fmt\.Println\("READY"\)`))
    44  			Eventually(session).Should(gbytes.Say(`>\s*time\.Sleep\(time\.Second\)`))
    45  
    46  			//first poll
    47  			Eventually(session).Should(gbytes.Say(`--poll-progress-after tracks things that take too long \(Spec Runtime: 1\.5\d*s\)`))
    48  			Eventually(session).Should(gbytes.Say(`>\s*time.Sleep\(2 \* time\.Second\)`))
    49  			Eventually(session).Should(gbytes.Say(`Begin Additional Progress Reports >>`))
    50  			Eventually(session).Should(gbytes.Say(`Some global information: 1`))
    51  			Eventually(session).Should(gbytes.Say(`<< End Additional Progress Reports`))
    52  
    53  			//second poll
    54  			Eventually(session).Should(gbytes.Say(`--poll-progress-after tracks things that take too long \(Spec Runtime: 1\.7\d*s\)`))
    55  			Eventually(session).Should(gbytes.Say(`>\s*time.Sleep\(2 \* time\.Second\)`))
    56  
    57  			//decorator poll
    58  			Eventually(session).Should(gbytes.Say(`decorator tracks things that take too long \(Spec Runtime: 5[\.\d]*ms\)`))
    59  			Eventually(session).Should(gbytes.Say(`>\s*time\.Sleep\(1 \* time\.Second\)`))
    60  
    61  			Eventually(session).Should(gexec.Exit(0))
    62  		})
    63  
    64  		It("allows the user to specify a source-root to find source code files", func() {
    65  			// first we build the test with -gcflags=all=-trimpath=<PATH TO SPEC> to ensure
    66  			// that stack traces do not contain absolute paths
    67  			path, err := filepath.Abs(fm.PathTo("progress_report"))
    68  			Ω(err).ShouldNot(HaveOccurred())
    69  			session := startGinkgo(fm.PathTo("progress_report"), "build", `-gcflags=-trimpath=`+path+``)
    70  			Eventually(session).Should(gexec.Exit(0))
    71  
    72  			// now we move the compiled test binary to a separate directory
    73  			fm.MkEmpty("progress_report/suite")
    74  			os.Rename(fm.PathTo("progress_report", "progress_report.test"), fm.PathTo("progress_report", "suite", "progress_report.test"))
    75  
    76  			//and we run and confirm that we don't see the expected source code
    77  			session = startGinkgo(fm.PathTo("progress_report", "suite"), "--poll-progress-after=1500ms", "--poll-progress-interval=200ms", "--no-color", "-label-filter=one-second", "./progress_report.test")
    78  			Eventually(session).Should(gexec.Exit(0))
    79  			Ω(session).ShouldNot(gbytes.Say(`>\s*time.Sleep\(1 \* time\.Second\)`))
    80  
    81  			// now we run, but configured with source-root and see that we have the file
    82  			// note that multipel source-roots can be passed in
    83  			session = startGinkgo(fm.PathTo("progress_report", "suite"), "--poll-progress-after=1500ms", "--poll-progress-interval=200ms", "--no-color", "-label-filter=one-second", "--source-root=/tmp", "--source-root="+path, "./progress_report.test")
    84  			Eventually(session).Should(gbytes.Say(`>\s*time\.Sleep\(1 \* time\.Second\)`))
    85  			Eventually(session).Should(gexec.Exit(0))
    86  		})
    87  
    88  		It("emits progress immediately and includes process information when running in parallel", func() {
    89  			session := startGinkgo(fm.PathTo("progress_report"), "--poll-progress-after=1500ms", "--poll-progress-interval=200ms", "--no-color", "-procs=2", "-label-filter=parallel")
    90  			Eventually(session).Should(gexec.Exit(0))
    91  
    92  			Eventually(session.Out.Contents()).Should(ContainSubstring(`Progress Report for Ginkgo Process #1`))
    93  			Eventually(session.Out.Contents()).Should(ContainSubstring(`Progress Report for Ginkgo Process #2`))
    94  			Eventually(session.Out.Contents()).Should(ContainSubstring(`Some global information: 1`))
    95  			Eventually(session.Out.Contents()).Should(ContainSubstring(`Some global information: 2`))
    96  
    97  		})
    98  
    99  	})
   100  })
   101  

View as plain text