By the time I ________ my homework, it was already midnight.
Correct: D
The correct answer is 'had finished' because it is in the past perfect tense, which is used to describe an action that happened before another action in the past. The sentence should read: 'By the time I had finished my homework, it was already midnight.'