Skip to content

Commit

Permalink
test(logging): add back DeleteLog test (#3114)
Browse files Browse the repository at this point in the history
fixes #1654 

To de-flake:
- Instead of calling Logs() which is flakey, we write a new log entry then do a single deletion
- Also verified with BE that the quota for all logadmin api calls is 600/min and 1k/hour

It might still flake for a new reason since DeleteLogs is getting deprecated and may be inherently flakey. I will monitor it.
  • Loading branch information
0xSage committed Oct 30, 2020
1 parent 258cb91 commit b66727a
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions logging/logging_test.go
Expand Up @@ -473,38 +473,27 @@ func TestPing(t *testing.T) {
}
}

func TestLogsAndDelete(t *testing.T) {
t.Skip("https://github.com/googleapis/google-cloud-go/issues/1654")

// This function tests both the Logs and DeleteLog methods. We only try to
// delete those logs that we can observe and that were generated by this
// test. This may not include the logs generated from the current test run,
// because the logging service is only eventually consistent. It's
// therefore possible that on some runs, this test will do nothing.
func TestDeleteLog(t *testing.T) {
ctx := context.Background()
it := aclient.Logs(ctx)
nDeleted := 0
for {
logID, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
t.Fatal(err)
}
if strings.HasPrefix(logID, testLogIDPrefix) {
if err := aclient.DeleteLog(ctx, logID); err != nil {
// Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find
// a log that is returned by Logs.
if status.Code(err) != codes.NotFound {
t.Fatalf("deleting %q: %v", logID, err)
}
} else {
nDeleted++
}
initLogs()
c, a := newClients(ctx, testProjectID)
defer c.Close()
defer a.Close()
lg := c.Logger(testLogID)

if err := lg.LogSync(ctx, logging.Entry{Payload: "hello"}); err != nil {
t.Fatal(err)
}

if err := aclient.DeleteLog(ctx, testLogID); err != nil {
// Ignore NotFound. Sometimes, amazingly, DeleteLog cannot find
// a log that is returned by Logs.
if status.Code(err) != codes.NotFound {
t.Fatalf("deleting %q: %v", testLogID, err)
}
} else {
t.Logf("deleted log_id: %q", testLogID)
}
t.Logf("deleted %d logs", nDeleted)
}

func TestNonProjectParent(t *testing.T) {
Expand Down

0 comments on commit b66727a

Please sign in to comment.