Run tests with -race flag in GoLand ?

To understand -race flag better, we can refer to the Go documentation:

Data races are among the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at …


This content originally appeared on DEV Community and was authored by Daniil Maslov

To understand -race flag better, we can refer to the Go documentation:

Data races are among the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write.

It is easy to use via the command line interface. So, how to use -race flag in GoLand with tests? Is it possible to use -race always in tests? Here you go.

Add -race flag to a specific test

  • Navigate to a test file, click on the gutter icon near the test name and select Modify Run Configuration. Gutter menu with the Modify Run Configuration entry
  • Add -race entry to the Go tool arguments field. Example of adding race flag
  • Save changes and run the configuration again.

Add -race flag to all tests

  • Navigate to Help | Find Action in the main menu (Shift+Shift by shortcuts) and type Edit Configurations, press Enter.
  • Select the Edit configuration templates option, find Go Test. Option is left-bottom position
  • Add -race entry to the Go tool arguments field. Pay attention that changing a template does not affect the existing configuration and you should add the flag manually to the same field.

Congratulations! ? Now your tests use -race flag and you can see warnings from the compiler. Example of warning from the compiler


This content originally appeared on DEV Community and was authored by Daniil Maslov


Print Share Comment Cite Upload Translate Updates
APA

Daniil Maslov | Sciencx (2021-06-29T09:14:06+00:00) Run tests with -race flag in GoLand ?. Retrieved from https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/

MLA
" » Run tests with -race flag in GoLand ?." Daniil Maslov | Sciencx - Tuesday June 29, 2021, https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/
HARVARD
Daniil Maslov | Sciencx Tuesday June 29, 2021 » Run tests with -race flag in GoLand ?., viewed ,<https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/>
VANCOUVER
Daniil Maslov | Sciencx - » Run tests with -race flag in GoLand ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/
CHICAGO
" » Run tests with -race flag in GoLand ?." Daniil Maslov | Sciencx - Accessed . https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/
IEEE
" » Run tests with -race flag in GoLand ?." Daniil Maslov | Sciencx [Online]. Available: https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/. [Accessed: ]
rf:citation
» Run tests with -race flag in GoLand ? | Daniil Maslov | Sciencx | https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.