Skip to content

Commit

Permalink
#55 Fix sigsegv on ListTasks when queue is already deleted (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
aertje authored Oct 24, 2022
1 parent 40e1a30 commit e7a514d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ func (s *Server) TestIamPermissions(ctx context.Context, in *v1.TestIamPermissio
// ListTasks lists the tasks in the specified queue
func (s *Server) ListTasks(ctx context.Context, in *tasks.ListTasksRequest) (*tasks.ListTasksResponse, error) {
// TODO: Implement pageing of some sort
queue, _ := s.fetchQueue(in.GetParent())
queue, ok := s.fetchQueue(in.GetParent())
if !ok || queue == nil {
return nil, status.Errorf(codes.NotFound, "Queue does not exist. If you just created the queue, wait at least a minute for the queue to initialize.")
}

var taskStates []*tasks.Task

Expand Down
51 changes: 51 additions & 0 deletions emulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,57 @@ func TestPurgeQueueOptionallyPerformsHardReset(t *testing.T) {
)
}

func TestListTasks(t *testing.T) {
serv, client := setUp(t, ServerOptions{})
defer tearDown(t, serv)

srv, _ := startTestServer()
defer srv.Shutdown(context.Background())

createdQueue := createTestQueue(t, client)

createTaskRequest := taskspb.CreateTaskRequest{
Parent: createdQueue.GetName(),
Task: &taskspb.Task{
Name: createdQueue.GetName() + "/tasks/my-test-task",
MessageType: &taskspb.Task_HttpRequest{
HttpRequest: &taskspb.HttpRequest{
Url: "http://localhost:5000/success",
},
},
},
}

createdTask, err := client.CreateTask(context.Background(), &createTaskRequest)
require.NoError(t, err)

listTasksRequest := taskspb.ListTasksRequest{
Parent: createdQueue.GetName(),
}

tasksIterator := client.ListTasks(context.Background(), &listTasksRequest)
assert.NoError(t, err)

listedTask, err := tasksIterator.Next()
assert.NoError(t, err)
assert.Equal(t, listedTask.GetName(), createdTask.GetName())
_, err = tasksIterator.Next()
assert.EqualError(t, err, "no more items in iterator")

deleteQueueRequest := taskspb.DeleteQueueRequest{
Name: createdQueue.GetName(),
}
err = client.DeleteQueue(context.Background(), &deleteQueueRequest)
require.NoError(t, err)

tasksIterator = client.ListTasks(context.Background(), &listTasksRequest)
assert.NoError(t, err)

listedTask, err = tasksIterator.Next()
assertIsGrpcError(t, "^Queue does not exist", grpcCodes.NotFound, err)
assert.Nil(t, listedTask)
}

func TestSuccessTaskExecution(t *testing.T) {
serv, client := setUp(t, ServerOptions{})
defer tearDown(t, serv)
Expand Down

0 comments on commit e7a514d

Please sign in to comment.