helper functions Wait for a file to show up in the filesystem then read its content.
(path string, timeout time.Duration)
| 1320 | |
| 1321 | // Wait for a file to show up in the filesystem then read its content. |
| 1322 | func waitForFileAndRead(path string, timeout time.Duration) ([]byte, error) { |
| 1323 | var ( |
| 1324 | deadline = time.After(timeout) |
| 1325 | slack = 100 * time.Millisecond |
| 1326 | ) |
| 1327 | |
| 1328 | WAIT: |
| 1329 | for { |
| 1330 | if _, err := os.Stat(path); err == nil { |
| 1331 | break WAIT |
| 1332 | } |
| 1333 | select { |
| 1334 | case <-deadline: |
| 1335 | return nil, fmt.Errorf("waiting for %s timed out", path) |
| 1336 | default: |
| 1337 | time.Sleep(slack) |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | time.Sleep(slack) |
| 1342 | return os.ReadFile(path) |
| 1343 | } |
| 1344 | |
| 1345 | // getAvailableCpuset returns the set of online CPUs. |
| 1346 | func getAvailableCpuset(t *testing.T) []string { |
no test coverage detected
searching dependent graphs…